-
Notifications
You must be signed in to change notification settings - Fork 7
GAP-4 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
5
commits 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 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6576bbe
GAP-0002 Add Field Extensions Spec
egoodwinx 27850f3
Merge branch 'main' into field-extensions
egoodwinx bceaeee
address comments and update location
egoodwinx 32e22ef
update numbering and sponsor
egoodwinx d77da13
do not add extend to field
egoodwinx 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 { | ||
| extend 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: 2 | ||
|
benjie marked this conversation as resolved.
Outdated
|
||
| title: Field Extensions | ||
| status: proposal | ||
| authors: | ||
| - "Emily Goodwin <goodwin.y.emily@gmail.com>" | ||
| - "Martin Bonnin <martin@mbonnin.net>" | ||
| sponsor: "@egoodwinx" | ||
|
benjie marked this conversation as resolved.
Outdated
|
||
| discussion: "https://github.com/graphql/graphql-spec/issues/1162" | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.