Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enum types valuemust be the same across source schemas #42

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions spec/Section 4 -- Composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved

- 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment enum value have to be strictly equal. We do not differentiate between output, input or combined enums

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment enum value have to be strictly equal

Do we plan to explore relaxing this to allow evolution of enums?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we just talked about this in yesterdays wg, we are probably going to use the same pattern that federation uses currently.
union in ouput, intersection in input and exact match if used as in- and output

PascalSenn marked this conversation as resolved.
Show resolved Hide resolved

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:
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved

```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
Expand Down