From 502bd166f6f4ea353cc8c4ad775f471d1ed38f3b Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Sun, 4 Aug 2024 20:33:51 +0200 Subject: [PATCH 1/7] Add enum types valuemust be the same across source schemas --- spec/Section 4 -- Composition.md | 52 ++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 35d3b72..683bda4 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -14,6 +14,58 @@ run in sequence to produce the composite execution schema. ### Pre Merge Validation +#### Enum Type Values Must Be The Same Across Source Schemas + +**Error Code** + +ENUM_VALUES_MUST_BE_THE_SAME_ACROSS_SCHEMAS + +**Formal Specification** + +- Let {enumsByName} be a map where the key is the name of an enum type, and the value is a list of all enum types from different source schemas with that name. +- For each {listOfEnum} in {enumsByName}: + - {EnumAreMergeable(listOfEnum)} must be true. + +EnumAreMergeable(enums): + +- Let {values} be the set of all values of the first enum in {enums} +- For each {enum} in {enums} + - Let {enumValues} be the set of all values of {enum} + - {values} must be equal to {enumValues} + +**Explanatory Text** + +This rule ensures that enum types with the same name across different source schemas in a composite schema have identical sets of values. +Enums, must be consistent across source schemas to avoid conflicts and ambiguities in the composite schema. + +When an enum is defined with differing values, it can lead to confusion and errors in query execution. +For instance, a value valid in one schema might be passed to another where it's unrecognized, leading to unexpected behavior or failures. +This rule prevents such inconsistencies by enforcing that all instances of the same named enum across schemas have an exact match in their values. + +In this example, both subgraphs define `Enum1` with the same value `BAR`, satisfying the rule: + +```graphql example +enum Enum1 { + BAR +} + +enum Enum1 { + BAR +} +``` + +Here, the two definitions of `Enum1` have different values (`BAR` and `Baz`), violating the rule: + +```graphql counter-example +enum Enum1 { + BAR +} + +enum Enum1 { + Baz +} +``` + ### Merge ### Post Merge Validation From 03378e9fdbfb94ec00e04fc7b3b78446bcfbeb2f Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Tue, 6 Aug 2024 02:10:10 +0200 Subject: [PATCH 2/7] Update spec/Section 4 -- Composition.md Co-authored-by: Glen --- spec/Section 4 -- Composition.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 683bda4..b3653a4 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -23,10 +23,10 @@ ENUM_VALUES_MUST_BE_THE_SAME_ACROSS_SCHEMAS **Formal Specification** - Let {enumsByName} be a map where the key is the name of an enum type, and the value is a list of all enum types from different source schemas with that name. -- For each {listOfEnum} in {enumsByName}: - - {EnumAreMergeable(listOfEnum)} must be true. +- For each {listOfEnums} in {enumsByName}: + - {EnumsAreMergeable(listOfEnums)} must be true. -EnumAreMergeable(enums): +EnumsAreMergeable(enums): - Let {values} be the set of all values of the first enum in {enums} - For each {enum} in {enums} From a9a8941ee4ec4f826b04b5f803745df45e1ca58c Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Tue, 6 Aug 2024 02:10:16 +0200 Subject: [PATCH 3/7] 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 b3653a4..0f6088a 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -42,7 +42,7 @@ When an enum is defined with differing values, it can lead to confusion and erro For instance, a value valid in one schema might be passed to another where it's unrecognized, leading to unexpected behavior or failures. This rule prevents such inconsistencies by enforcing that all instances of the same named enum across schemas have an exact match in their values. -In this example, both subgraphs define `Enum1` with the same value `BAR`, satisfying the rule: +In this example, both source schemas define `Enum1` with the same value `BAR`, satisfying the rule: ```graphql example enum Enum1 { From 2c042db645a1f200345aac00bd5adb1ae230a446 Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Thu, 7 Nov 2024 15:25:57 +0100 Subject: [PATCH 4/7] Cleanup rule --- spec/Section 4 -- Composition.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/spec/Section 4 -- Composition.md b/spec/Section 4 -- Composition.md index 0f6088a..1ab2510 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -22,16 +22,18 @@ ENUM_VALUES_MUST_BE_THE_SAME_ACROSS_SCHEMAS **Formal Specification** -- Let {enumsByName} be a map where the key is the name of an enum type, and the value is a list of all enum types from different source schemas with that name. -- For each {listOfEnums} in {enumsByName}: - - {EnumsAreMergeable(listOfEnums)} must be true. +- Let {enumNames} be the set of all enum type names across all source schemas. +- For each {enumName} in {enumNames}: + - Let {enums} be the list of all enum types from different source schemas with the name {enumName}. + - {EnumsAreMergeable(enums)} must be true. EnumsAreMergeable(enums): -- Let {values} be the set of all values of the first enum in {enums} +- Let {inaccessibleValues} be the set of values that are declared as `@inaccessible` in {enums}. +- Let {requriedValues} be the set of values in {enums} that are not in {inaccessibleValues}. - For each {enum} in {enums} - - Let {enumValues} be the set of all values of {enum} - - {values} must be equal to {enumValues} + - Let {enumValues} be the set of all values of {enum} that are not in {inaccessibleValues}. + - {requriedValues} must be equal to {enumValues} **Explanatory Text** @@ -66,6 +68,19 @@ enum Enum1 { } ``` +Here, the two definitions of `Enum1` have shared values and additional values declared as `@inaccessible`, satisfying the rule: + +```graphql example +enum Enum1 { + BAR + BAZ @inaccessible +} + +enum Enum1 { + BAR +} +``` + ### Merge ### Post Merge Validation From bcbc01f515c06005276b5b517cda32f27bcbf37e Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Thu, 7 Nov 2024 15:26:38 +0100 Subject: [PATCH 5/7] Cleanup rule --- 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 1ab2510..f91aa1a 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -38,7 +38,7 @@ EnumsAreMergeable(enums): **Explanatory Text** This rule ensures that enum types with the same name across different source schemas in a composite schema have identical sets of values. -Enums, must be consistent across source schemas to avoid conflicts and ambiguities in the composite schema. +Enums must be consistent across source schemas to avoid conflicts and ambiguities in the composite schema. When an enum is defined with differing values, it can lead to confusion and errors in query execution. For instance, a value valid in one schema might be passed to another where it's unrecognized, leading to unexpected behavior or failures. From f6be520987659119809ce551bad47c9dd58a3e7e Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Wed, 13 Nov 2024 19:18:00 +0100 Subject: [PATCH 6/7] 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 f91aa1a..aeece56 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -33,7 +33,7 @@ EnumsAreMergeable(enums): - Let {requriedValues} be the set of values in {enums} that are not in {inaccessibleValues}. - For each {enum} in {enums} - Let {enumValues} be the set of all values of {enum} that are not in {inaccessibleValues}. - - {requriedValues} must be equal to {enumValues} + - {requiredValues} must be equal to {enumValues} **Explanatory Text** From 5d7e2fd21bc25585f72032fa6d8307bf6c9ca80e Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Wed, 13 Nov 2024 19:18:05 +0100 Subject: [PATCH 7/7] 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 aeece56..ecd3b65 100644 --- a/spec/Section 4 -- Composition.md +++ b/spec/Section 4 -- Composition.md @@ -30,7 +30,7 @@ ENUM_VALUES_MUST_BE_THE_SAME_ACROSS_SCHEMAS EnumsAreMergeable(enums): - Let {inaccessibleValues} be the set of values that are declared as `@inaccessible` in {enums}. -- Let {requriedValues} be the set of values in {enums} that are not in {inaccessibleValues}. +- Let {requiredValues} be the set of values in {enums} that are not in {inaccessibleValues}. - For each {enum} in {enums} - Let {enumValues} be the set of all values of {enum} that are not in {inaccessibleValues}. - {requiredValues} must be equal to {enumValues}