diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 35d3b72..2d90a0c 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -14,6 +14,69 @@ run in sequence to produce the composite execution schema. ### Pre Merge Validation +#### Semantic Equivalence of Types + +**Error Code** + +`TYPE_KIND_NOT_MERGEABLE` + +**Formal Specification** + +- Let {typesByName} be an empty unordered map of sets. +- For each named type {type} across all source schemas: + - Let {name} be the name of {type}. + - Let {set} be the set in {typesByName} for {name}; if no such set exists, + create it as an empty set. + - Add {type} to {set}. +- For each {typesByName} as {name} and {types}: + - Each pair of types in {types} must have the same kind. + +**Explanatory Text** + +The GraphQL Composite Schemas specification considers types with the same name +across source schemas as semantically equivalent and mergeable. + +For the schema composition process to be able to merge types with the +same name, the types must have the same kind. In this example we have two types +called `User` which are both object types and are mergeable. + +```graphql example +type User { + id: ID! + name: String! + displayName: String! + birthdate: String! +} + +type User { + id: ID! + name: String! + reviews: [Review!] +} +``` + +However, if the second type were a scalar type, the types would not be +mergeable as they have different kinds. + +```graphql counter-example +type User { + id: ID! + name: String! + displayName: String! + birthdate: String! +} + +scalar User +``` + +All types with the same name must have the same kind to be mergeable. + +```graphql example +scalar User + +scalar User +``` + ### Merge ### Post Merge Validation