-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow deprecation of input values (field args, directive args, input fields) #805
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
Changes from 6 commits
0e1f9b8
6ad62e8
cce1219
23f175c
ba78f00
d3dd6f7
127f0ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -879,6 +879,8 @@ of rules must be adhered to by every Object type in a GraphQL schema. | |
{"\_\_"} (two underscores). | ||
2. The argument must accept a type where {IsInputType(argumentType)} | ||
returns {true}. | ||
3. If argument type is Non-Null and a default value is not defined: | ||
- The `@deprecated` directive shall not be applied to this argument. | ||
3. An object type may declare that it implements one or more unique interfaces. | ||
4. An object type must be a super-set of all interfaces it implements: | ||
1. Let this object type be {objectType}. | ||
|
@@ -1652,6 +1654,8 @@ input ExampleInputObject { | |
{"\_\_"} (two underscores). | ||
3. The input field must accept a type where {IsInputType(inputFieldType)} | ||
returns {true}. | ||
4. If input field type is Non-Null and a default value is not defined: | ||
- The `@deprecated` directive shall not be applied to this input field. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
3. If an Input Object references itself either directly or through referenced | ||
Input Objects, at least one of the fields in the chain of references must be | ||
either a nullable or a List type. | ||
|
@@ -2047,26 +2051,47 @@ condition is false. | |
```graphql | ||
directive @deprecated( | ||
reason: String = "No longer supported" | ||
) on FIELD_DEFINITION | ENUM_VALUE | ||
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION | ENUM_VALUE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
``` | ||
|
||
The `@deprecated` _built-in directive_ is used within the type system definition | ||
language to indicate deprecated portions of a GraphQL service's schema, such as | ||
deprecated fields on a type or deprecated enum values. | ||
deprecated fields on a type, arguments on a field, input fields on an input | ||
type, or values of an enum type. | ||
|
||
Deprecations include a reason for why it is deprecated, which is formatted using | ||
Markdown syntax (as specified by [CommonMark](https://commonmark.org/)). | ||
|
||
In this example type definition, `oldField` is deprecated in favor of using | ||
`newField`. | ||
`newField` and `oldArg` is deprecated in favor of using `newArg`. | ||
|
||
```graphql example | ||
type ExampleType { | ||
newField: String | ||
oldField: String @deprecated(reason: "Use `newField`.") | ||
|
||
anotherField( | ||
newArg: String | ||
oldArg: String @deprecated(reason: "Use `newArg`.") | ||
): String | ||
} | ||
``` | ||
|
||
The `@deprecated` directive must not appear on required (non-null without a | ||
default) arguments or input object field definitions. | ||
|
||
```graphql counter-example | ||
type ExampleType { | ||
invalidField( | ||
newArg: String | ||
oldArg: String! @deprecated(reason: "Use `newArg`.") | ||
): String | ||
} | ||
``` | ||
|
||
A required argument or input field should first be made optional by either | ||
changing the type to nullable or adding a default value. | ||
|
||
### @specifiedBy | ||
|
||
```graphql | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,9 +108,10 @@ CommonMark-compliant Markdown renderer. | |
|
||
**Deprecation** | ||
|
||
To support the management of backwards compatibility, GraphQL fields and enum | ||
values can indicate whether or not they are deprecated (`isDeprecated: Boolean`) | ||
and a description of why it is deprecated (`deprecationReason: String`). | ||
To support the management of backwards compatibility, GraphQL fields, arguments, | ||
input fields, and enum values can indicate whether or not they are deprecated | ||
(`isDeprecated: Boolean`) along with a description of why it is deprecated | ||
(`deprecationReason: String`). | ||
|
||
Tools built using GraphQL introspection should respect deprecation by | ||
discouraging deprecated use through information hiding or developer-facing | ||
|
@@ -145,7 +146,7 @@ type __Type { | |
# must be non-null for ENUM, otherwise null. | ||
enumValues(includeDeprecated: Boolean = false): [__EnumValue!] | ||
# must be non-null for INPUT_OBJECT, otherwise null. | ||
inputFields: [__InputValue!] | ||
inputFields(includeDeprecated: Boolean = false): [__InputValue!] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# must be non-null for NON_NULL and LIST, otherwise null. | ||
ofType: __Type | ||
# may be non-null for custom SCALAR, otherwise null. | ||
|
@@ -166,7 +167,7 @@ enum __TypeKind { | |
type __Field { | ||
name: String! | ||
description: String | ||
args: [__InputValue!]! | ||
args(includeDeprecated: Boolean = false): [__InputValue!]! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
type: __Type! | ||
isDeprecated: Boolean! | ||
deprecationReason: String | ||
|
@@ -177,6 +178,8 @@ type __InputValue { | |
description: String | ||
type: __Type! | ||
defaultValue: String | ||
isDeprecated: Boolean! | ||
deprecationReason: String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
type __EnumValue { | ||
|
@@ -190,7 +193,7 @@ type __Directive { | |
name: String! | ||
description: String | ||
locations: [__DirectiveLocation!]! | ||
args: [__InputValue!]! | ||
args(includeDeprecated: Boolean = false): [__InputValue!]! | ||
michaelstaib marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
isRepeatable: Boolean! | ||
} | ||
|
||
|
@@ -367,6 +370,8 @@ Fields\: | |
- `name` must return a String. | ||
- `description` may return a String or {null}. | ||
- `inputFields` must return the set of input fields as a list of `__InputValue`. | ||
- Accepts the argument `includeDeprecated` which defaults to {false}. If | ||
{true}, deprecated fields are also returned. | ||
- All other fields must return {null}. | ||
|
||
**List** | ||
|
@@ -412,6 +417,8 @@ Fields\: | |
- `description` may return a String or {null} | ||
- `args` returns a List of `__InputValue` representing the arguments this field | ||
accepts. | ||
- Accepts the argument `includeDeprecated` which defaults to {false}. If | ||
{true}, deprecated arguments are also returned. | ||
- `type` must return a `__Type` that represents the type of value returned by | ||
this field. | ||
- `isDeprecated` returns {true} if this field should no longer be used, | ||
|
@@ -432,6 +439,10 @@ Fields\: | |
- `defaultValue` may return a String encoding (using the GraphQL language) of | ||
the default value used by this input value in the condition a value is not | ||
provided at runtime. If this input value has no default value, returns {null}. | ||
- `isDeprecated` returns {true} if this input field or argument should no longer | ||
be used, otherwise {false}. | ||
- `deprecationReason` optionally provides a reason why this input field or | ||
argument is deprecated. | ||
|
||
### The \_\_EnumValue Type | ||
|
||
|
@@ -483,5 +494,7 @@ Fields\: | |
locations this directive may be placed. | ||
- `args` returns a List of `__InputValue` representing the arguments this | ||
directive accepts. | ||
- Accepts the argument `includeDeprecated` which defaults to {false}. If | ||
{true}, deprecated arguments are also returned. | ||
- `isRepeatable` must return a Boolean that indicates if the directive may be | ||
used repeatedly at a single location. |
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.
Implemented here:
https://github.com/graphql/graphql-js/blob/5740cbdb58d3b50a11a29b24869a35a7ae8b6588/src/type/validate.ts#L191-L196
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.
and here https://github.com/graphql/graphql-js/blob/5740cbdb58d3b50a11a29b24869a35a7ae8b6588/src/type/validate.ts#L304-L308