Skip to content

Commit

Permalink
Adds Empty Object Type Validation Rule (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: PascalSenn <[email protected]>
  • Loading branch information
michaelstaib and PascalSenn authored Nov 7, 2024
1 parent 3800161 commit 8719bdf
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions spec/Section 4 -- Composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,84 @@ run in sequence to produce the composite execution schema.

### Post Merge Validation

#### Empty Merged Object Type

**Error Code**

`EMPTY_MERGED_OBJECT_TYPE`

**Severity** ERROR

**Formal Specification**

- Let {types} be the set of all object types across all source schemas
- For each {type} in {types}:
- {IsObjectTypeEmpty(type)} must be false.

IsObjectTypeEmpty(type):

- If {type} has `@inaccessible` directive
- return false
- Let {fields} be a set of all fields in {type}
- For each {field} in {fields}:
- If {IsExposed(field)} is true
- return false
- return true

**Explanatory Text**

For object types defined across multiple source schemas, the merged object type
is the superset of all fields defined in these source schemas. However, any
field marked with `@inaccessible` in any source schema is hidden and not
included in the merged object type. An object type with no fields, after
considering `@inaccessible` annotations, is considered empty and invalid.

In the following example, the merged object type `ObjectType1` is valid. It
includes all fields from both source schemas, with `field2` being hidden due to
the `@inaccessible` directive in one of the source schemas:

```graphql
type ObjectType1 {
field1: String
field2: Int @inaccessible
}

type ObjectType1 {
field2: Int
field3: Boolean
}
```

If the `@inaccessible` directive is applied to an object type itself, the entire
merged object type is excluded from the composite execution schema, and it is
not required to contain any fields.

```graphql
type ObjectType1 @inaccessible {
field1: String
field2: Int
}

type ObjectType1 {
field3: Boolean
}
```

This counter-example demonstrates an invalid merged object type. In this case,
`ObjectType1` is defined in two source schemas, but all fields are marked as
`@inaccessible` in at least one of the source schemas, resulting in an empty
merged object type:

```graphql counter-example
type ObjectType1 {
field1: String @inaccessible
field2: Boolean
}

type ObjectType1 {
field1: String
field2: Boolean @inaccessible
}
```

## Validate Satisfiability

0 comments on commit 8719bdf

Please sign in to comment.