-
Notifications
You must be signed in to change notification settings - Fork 4
GAP-0002 Add Field Extensions Spec #4
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
Open
egoodwinx
wants to merge
1
commit into
graphql:main
Choose a base branch
from
egoodwinx:field-extensions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| ## Overview | ||
|
|
||
| Interface type extensions may extend existing fields. | ||
|
|
||
| In this example, we deprecate the field `id` on type `Query` by adding a | ||
| `@deprecated` directive: | ||
|
|
||
| ```graphql example | ||
| type Query { | ||
| id: ID | ||
| } | ||
| ``` | ||
|
|
||
| ```graphql example | ||
| extend type Query { | ||
| id: ID @deprecated(reason: "Use globalId instead") | ||
| } | ||
| ``` | ||
|
|
||
| For each field of an Object type extension: | ||
|
|
||
| 1. The field must have a unique name within that 2. If a field with the same name exists on the previous Object type: | ||
| type extension; no | ||
| two fields may share the same name. | ||
| 2. If a field with the same name exists on the previous Object type: | ||
| 1. The field type must match the previous definition exactly. | ||
| 2. The field description must match the previous definition exactly. | ||
| 3. Any non-repeatable directives provided must not already apply to the | ||
| previous definition. | ||
| 4. For each argument of the field: | ||
| 1. If an argument with the same name exists on the previous field | ||
| definition: | ||
| 1. The argument type must match the previous definition exactly. | ||
| 2. If the argument has a default value, it must match the previous | ||
| definition exactly or not be added. | ||
| 3. The argument description must match the previous definition | ||
| exactly or not be added. | ||
| 4. Any non-repeatable directives provided must not already apply to | ||
| the previous definition. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| ## Problem statement | ||
|
|
||
| The current GraphQL specification allows type system extensions. | ||
|
|
||
| For example, it is possible to add directives to an existing type. In this example (from the specification text), a directive is added to a User type without adding fields: | ||
|
|
||
| ```graphql | ||
| extend type User @addedDirective | ||
| ``` | ||
|
|
||
| The same thing is not possible for fields: | ||
|
|
||
| ```graphql | ||
| # This is not valid GraphQL | ||
| extend type User { | ||
| id: ID! @key | ||
| } | ||
| ``` | ||
|
|
||
| This has been an ongoing pain point when working in clients that do not own the schema but want to annotate it for codegen or other reasons. In Apollo Kotlin, this has led to the proliferation of directives ending in \*Field whose only goal is to work around that limitation. For an example, this is happening in the nullability directives: | ||
|
|
||
| ```graphql | ||
| # This can be added to a field definition directly | ||
| directive @semanticNonNull(levels: [Int!]! = [0]) on FIELD_DEFINITION | ||
| ``` | ||
|
|
||
| ```graphql | ||
| # This is the same thing but on the containing type. | ||
| # It is more verbose and cumbersome to write and maintain | ||
| directive @semanticNonNullField( | ||
| name: String! | ||
| levels: [Int!]! = [0] | ||
| ) repeatable on OBJECT | INTERFACE | ||
| ``` | ||
|
|
||
| ## Overview | ||
|
|
||
| This GAP builds on the current ability to extend types and further allows extending existing fields. | ||
|
|
||
| Interface type extensions may extend existing fields. | ||
|
|
||
| In this example, we deprecate the field `id` on type `Query` by adding a | ||
| `@deprecated` directive: | ||
|
|
||
| ```graphql example | ||
| type Query { | ||
| id: ID | ||
| } | ||
| ``` | ||
|
|
||
| ```graphql example | ||
| extend type Query { | ||
| id: ID @deprecated(reason: "Use globalId instead") | ||
| } | ||
| ``` | ||
|
|
||
| For each field of an Object type extension: | ||
|
|
||
| 1. The field must have a unique name within that 2. If a field with the same name exists on the previous Object type: | ||
| type extension; no | ||
| two fields may share the same name. | ||
| 2. If a field with the same name exists on the previous Object type: | ||
| 1. The field type must match the previous definition exactly. | ||
| 2. The field description must match the previous definition exactly. | ||
| 3. Any non-repeatable directives provided must not already apply to the | ||
| previous definition. | ||
| 4. For each argument of the field: | ||
| 1. If an argument with the same name exists on the previous field | ||
| definition: | ||
| 1. The argument type must match the previous definition exactly. | ||
| 2. If the argument has a default value, it must match the previous | ||
| definition exactly or not be added. | ||
| 3. The argument description must match the previous definition | ||
| exactly or not be added. | ||
| 4. Any non-repeatable directives provided must not already apply to | ||
| the previous definition. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| id: 0002 | ||
| title: Field Extensions | ||
| status: proposal | ||
| authors: | ||
| - "Emily Goodwin <goodwin.y.emily@gmail.com>" | ||
| - "Martin Bonnin <martin@mbonnin.net>" | ||
| sponsor: "@egoodwinx" | ||
| discussion: "https://github.com/graphql/graphql-spec/issues/1162" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think it would be cleaner to do:
Basically you're being explicit that this field DOES already exist but you're adding more to it.
I have this exact situation and have an internal representation that we actually see that I can't do a round trip into the SDL and back into SchemaSet in https://github.com/facebook/relay/blob/main/compiler/crates/schema-set/src/set_exclude.rs#L413