From bdf5886edfe784ec0da6fd27b186c35cf15d517f Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 19:01:20 +0200 Subject: [PATCH 01/11] Adds input with differnt fields to composition --- spec/Section 4 -- Composition.md | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 35d3b72..8d6b982 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -14,6 +14,62 @@ run in sequence to produce the composite execution schema. ### Pre Merge Validation +#### Input With Different Fields + +**Error Code** + +INPUT_OBJECT_FIELDS_DIFFER + +**Formal Specification** + +- Let {inputsByName} be a map where the key is the name of an input object type, and the value is a list of all input object types from different source schemas with that name. +- For each {listOfInputs} in {inputsByName}: + - {InputFieldsAreMergeable(listOfInputs)} must be true. + +InputFieldsAreMergeable(inputs): + +- Let {fields} be the set of all field names of the first input object in + {inputs}. +- For each {input} in {inputs}: + - Let {inputFields} be the set of all field names of {input}. + - {fields} must be equal to {inputFields}. + +**Explanatory Text** + +This rule ensures that input object types with the same name across different subgraphs have identical sets of field names. +Consistency in input object fields across subgraphs is required to avoid conflicts and ambiguities in the composed schema. +This rule only checks that the field names are the same, not that the field types are the same. +Field types are checked by the [Input Field Types mergeable](#sec-Input-Field-Types-mergeable) rule. + +When an input object is defined with differing fields across subgraphs, it can lead to issues in query execution. +A field expected in one subgraph might be absent in another, leading to undefined behavior. +This rule prevents such inconsistencies by enforcing that all instances of the same named input object across subgraphs have a matching set of field names. + +In this example, both subgraphs define `Input1` with the same field `field1`, satisfying the rule: + +```graphql example +input Input1 { + field1: String +} + +input Input1 { + field1: String +} +``` + +Here, the two definitions of `Input1` have different fields (`field1` and `field2`), violating the rule: + +```graphql counter-example +input Input1 { + field1: String +} + +input Input1 { + field2: String +} +``` + + ### Merge ### Post Merge Validation From 95d5ec4b3d77f6ecefa180c5721f1b752d0c15d3 Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 19:01:42 +0200 Subject: [PATCH 02/11] Adds input with differnt fields to composition --- spec/Section 4 -- Composition.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 8d6b982..f542a2c 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -28,8 +28,7 @@ INPUT_OBJECT_FIELDS_DIFFER InputFieldsAreMergeable(inputs): -- Let {fields} be the set of all field names of the first input object in - {inputs}. +- Let {fields} be the set of all field names of the first input object in {inputs}. - For each {input} in {inputs}: - Let {inputFields} be the set of all field names of {input}. - {fields} must be equal to {inputFields}. From d073806beb655a5fce17c7c48b70d5f1b0122c6e Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 20:31:09 +0200 Subject: [PATCH 03/11] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index f542a2c..2f886f9 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -35,7 +35,7 @@ InputFieldsAreMergeable(inputs): **Explanatory Text** -This rule ensures that input object types with the same name across different subgraphs have identical sets of field names. +This rule ensures that input object types with the same name across different source schemas have identical sets of field names. Consistency in input object fields across subgraphs is required to avoid conflicts and ambiguities in the composed schema. This rule only checks that the field names are the same, not that the field types are the same. Field types are checked by the [Input Field Types mergeable](#sec-Input-Field-Types-mergeable) rule. From 54f2927f9cb4b25b1c7adc843e2def047b0c59f6 Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 20:31:17 +0200 Subject: [PATCH 04/11] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 2f886f9..9b8b8c4 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -36,7 +36,7 @@ InputFieldsAreMergeable(inputs): **Explanatory Text** This rule ensures that input object types with the same name across different source schemas have identical sets of field names. -Consistency in input object fields across subgraphs is required to avoid conflicts and ambiguities in the composed schema. +Consistency in input object fields across source schemas is required to avoid conflicts and ambiguities in the composed schema. This rule only checks that the field names are the same, not that the field types are the same. Field types are checked by the [Input Field Types mergeable](#sec-Input-Field-Types-mergeable) rule. From ba435372942789998313d62542d4c58927fed274 Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 20:31:24 +0200 Subject: [PATCH 05/11] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 9b8b8c4..4ebf861 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -40,7 +40,7 @@ Consistency in input object fields across source schemas is required to avoid co This rule only checks that the field names are the same, not that the field types are the same. Field types are checked by the [Input Field Types mergeable](#sec-Input-Field-Types-mergeable) rule. -When an input object is defined with differing fields across subgraphs, it can lead to issues in query execution. +When an input object is defined with differing fields across source schemas, it can lead to issues in query execution. A field expected in one subgraph might be absent in another, leading to undefined behavior. This rule prevents such inconsistencies by enforcing that all instances of the same named input object across subgraphs have a matching set of field names. From 3b6743993ba4dc1b4a32d1beaa5d53d40ac1831d Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 20:31:33 +0200 Subject: [PATCH 06/11] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 4ebf861..647f00b 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -41,7 +41,7 @@ This rule only checks that the field names are the same, not that the field type Field types are checked by the [Input Field Types mergeable](#sec-Input-Field-Types-mergeable) rule. When an input object is defined with differing fields across source schemas, it can lead to issues in query execution. -A field expected in one subgraph might be absent in another, leading to undefined behavior. +A field expected in one source schema might be absent in another, leading to undefined behavior. This rule prevents such inconsistencies by enforcing that all instances of the same named input object across subgraphs have a matching set of field names. In this example, both subgraphs define `Input1` with the same field `field1`, satisfying the rule: From 7b0398b2669ac1ee1caa18b7e83bdb974875267d Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 20:31:38 +0200 Subject: [PATCH 07/11] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 647f00b..9a38281 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -42,7 +42,7 @@ Field types are checked by the [Input Field Types mergeable](#sec-Input-Field-Ty When an input object is defined with differing fields across source schemas, it can lead to issues in query execution. A field expected in one source schema might be absent in another, leading to undefined behavior. -This rule prevents such inconsistencies by enforcing that all instances of the same named input object across subgraphs have a matching set of field names. +This rule prevents such inconsistencies by enforcing that all instances of the same named input object across source schemas have a matching set of field names. In this example, both subgraphs define `Input1` with the same field `field1`, satisfying the rule: From 1847dfa315ee667d0fef5253828186ea832b624e Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 20:31:43 +0200 Subject: [PATCH 08/11] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 9a38281..bf8486b 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -44,7 +44,7 @@ When an input object is defined with differing fields across source schemas, it A field expected in one source schema might be absent in another, leading to undefined behavior. This rule prevents such inconsistencies by enforcing that all instances of the same named input object across source schemas have a matching set of field names. -In this example, both subgraphs define `Input1` with the same field `field1`, satisfying the rule: +In this example, both source schemas define `Input1` with the same field `field1`, satisfying the rule: ```graphql example input Input1 { From c50924a693b7feb46d2c2ebd40305002eba0b0aa Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 20:31:48 +0200 Subject: [PATCH 09/11] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index bf8486b..ddcecc5 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -68,7 +68,6 @@ input Input1 { } ``` - ### Merge ### Post Merge Validation From 5732570a40e6d4481a157dea778d676622fa63b0 Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Thu, 7 Nov 2024 15:14:48 +0100 Subject: [PATCH 10/11] Cleanup rule --- spec/Section 4 -- Composition.md | 72 ++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index ddcecc5..673f853 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -14,60 +14,80 @@ run in sequence to produce the composite execution schema. ### Pre Merge Validation -#### Input With Different Fields +#### **Input With Missing Required Fields** -**Error Code** +**Error Code:** -INPUT_OBJECT_FIELDS_DIFFER +REQUIRED_INPUT_FIELD_MISSING_IN_SOME_SUBGRAPH -**Formal Specification** +**Severity:** -- Let {inputsByName} be a map where the key is the name of an input object type, and the value is a list of all input object types from different source schemas with that name. -- For each {listOfInputs} in {inputsByName}: - - {InputFieldsAreMergeable(listOfInputs)} must be true. +ERROR -InputFieldsAreMergeable(inputs): +**Formal Specification:** -- Let {fields} be the set of all field names of the first input object in {inputs}. -- For each {input} in {inputs}: - - Let {inputFields} be the set of all field names of {input}. - - {fields} must be equal to {inputFields}. +- Let {typeNames} be the set of all input object types from all source schemas that are not declared as `@inaccessible`. +- For each {typeName} in {typeNames}: + - Let `{types}` be the list of all input object types from different source schemas with the name {typeName}. + - `{AreTypesConsistent(types)}` must be true. + +**Function Definition:** + +`AreTypesConsistent(inputs):` + +- Let `{requiredFields}` be the intersection of all required field names across all input objects in `{inputs}`. +- For each `{input}` in `{inputs}`: + - Let `{inputFields}` be the set of all field names in of required fields in `{input}`. + - `{inputFields}` must equal `{requiredFields}`. **Explanatory Text** -This rule ensures that input object types with the same name across different source schemas have identical sets of field names. -Consistency in input object fields across source schemas is required to avoid conflicts and ambiguities in the composed schema. -This rule only checks that the field names are the same, not that the field types are the same. -Field types are checked by the [Input Field Types mergeable](#sec-Input-Field-Types-mergeable) rule. +Input types are merged by intersection, meaning that the merged input type will have all fields that are present in all input types with the same name. +This rule ensures that input object types with the same name across different subgraphs share a consistent set of required fields. + +When an input object is defined across multiple subgraphs, this rule ensures that any required field present in one subgraph is present in all others defining the input object. +This allows for reliable usage of input objects in queries across subgraphs. + +### Examples -When an input object is defined with differing fields across source schemas, it can lead to issues in query execution. -A field expected in one source schema might be absent in another, leading to undefined behavior. -This rule prevents such inconsistencies by enforcing that all instances of the same named input object across source schemas have a matching set of field names. +**Valid Example:** -In this example, both source schemas define `Input1` with the same field `field1`, satisfying the rule: +If all subgraphs define `Input1` with the required field `field1`, the rule is satisfied: -```graphql example +```graphql +# Subgraph 1 input Input1 { - field1: String + field1: String! + field2: String } +# Subgraph 2 input Input1 { - field1: String + field1: String! + field3: Int } ``` -Here, the two definitions of `Input1` have different fields (`field1` and `field2`), violating the rule: +**Invalid Example:** + +If `field1` is required in one subgraph but missing in another, this violates the rule: -```graphql counter-example +```graphql +# Subgraph 1 input Input1 { - field1: String + field1: String! + field2: String } +# Subgraph 2 input Input1 { field2: String + field3: Int } ``` +In this invalid case, `field1` is mandatory in `Subgraph 1` but not defined in `Subgraph 2`, causing inconsistency in required fields across subgraphs. + ### Merge ### Post Merge Validation From a06de3b5f6bafb03ef59329440699cce0ad8d557 Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Tue, 31 Dec 2024 15:24:03 +0100 Subject: [PATCH 11/11] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 673f853..4d33c84 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -37,7 +37,7 @@ ERROR - Let `{requiredFields}` be the intersection of all required field names across all input objects in `{inputs}`. - For each `{input}` in `{inputs}`: - - Let `{inputFields}` be the set of all field names in of required fields in `{input}`. + - Let `{inputFields}` be the set of all field names of required fields in `{input}`. - `{inputFields}` must equal `{requiredFields}`. **Explanatory Text**