diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 6b6232c..1ea1a52 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -14,6 +14,107 @@ run in sequence to produce the composite execution schema. ### Pre Merge Validation +#### Output Field Types Mergeable + +**Error Code** + +OUTPUT_FIELD_TYPES_NOT_MERGEABLE + +**Severity** + +ERROR + +**Formal Specification** + +- Let {typeNames} be the set of all output type names from all source schemas. +- For each {typeName} in {typeNames} + - Let {types} be the set of all types with the name {typeName} from all source + schemas. + - Let {fieldNames} be the set of all field names from all {types}. + - For each {fieldName} in {fieldNames} + - Let {fields} be the set of all fields with the name {fieldName} from all + {types}. + - {FieldsAreMergeable(fields)} must be true. + +FieldsAreMergeable(fields): + +- Given each pair of members {fieldA} and {fieldB} in {fields}: + - Let {typeA} be the type of {fieldA} + - Let {typeB} be the type of {fieldB} + - {SameOutputTypeShape(typeA, typeB)} must be true. + +**Explanatory Text** + +Fields on objects or interfaces that have the same name are considered +semantically equivalent and mergeable when they have a mergeable field type. + +Fields with the same type are mergeable. + +```graphql example +type User { + birthdate: String +} + +type User { + birthdate: String +} +``` + +Fields with different nullability are mergeable, resulting in a merged field +with a nullable type. + +```graphql example +type User { + birthdate: String! +} + +type User { + birthdate: String +} +``` + +```graphql example +type User { + tags: [String!] +} + +type User { + tags: [String]! +} + +type User { + tags: [String] +} +``` + +Fields are not mergeable if the named types are different in kind or name. + +```graphql counter-example +type User { + birthdate: String! +} + +type User { + birthdate: DateTime! +} +``` + +```graphql counter-example +type User { + tags: [Tag] +} + +type Tag { + value: String +} + +type User { + tags: [Tag] +} + +scalar Tag +``` + ### Merge ### Post Merge Validation