Skip to content

Commit ff20cb4

Browse files
committed
Add validation for @deprecated on required arguments
The `@deprecated` directive must not appear on required (non-null without a default) arguments or input object field definitions. Deprecated arguments and fields are excluded by default in introspection, and deprecating required arguments or input fields could create confusion for clients.
1 parent 42a9a94 commit ff20cb4

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

spec/Section 3 -- Type System.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,6 +2060,22 @@ type ExampleType {
20602060
}
20612061
```
20622062

2063+
The `@deprecated` directive must not appear on required (non-null without a default)
2064+
arguments or input object field definitions. Deprecated arguments and fields are
2065+
excluded by default in introspection, and deprecating required arguments or
2066+
input fields could create confusion for clients.
2067+
2068+
```graphql counter-example
2069+
type ExampleType {
2070+
invalidField(
2071+
newArg: String
2072+
oldArg: String! @deprecated(reason: "Use `newArg`.")
2073+
): String
2074+
}
2075+
```
2076+
2077+
A required argument or input field should first be made optional by either
2078+
changing the type to nullable or adding a default value.
20632079

20642080
### @specifiedBy
20652081

spec/Section 5 -- Validation.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ and invalid.
738738
* Let {argumentName} be the name of {argumentDefinition}.
739739
* Let {argument} be the argument in {arguments} named {argumentName}
740740
* {argument} must exist.
741+
* {argument} must not be deprecated.
741742
* Let {value} be the value of {argument}.
742743
* {value} must not be the {null} literal.
743744

@@ -785,6 +786,18 @@ fragment missingRequiredArg on Arguments {
785786
}
786787
```
787788

789+
If an argument is required (non-null without a default value), it must not be
790+
marked as deprecated.
791+
792+
```graphql counter-example
793+
type Query {
794+
"""
795+
This is invalid because the locale argument is both required and deprecated.
796+
"""
797+
myName(locale: String! @deprecated): String
798+
}
799+
```
800+
788801
## Fragments
789802

790803
### Fragment Declarations
@@ -1419,6 +1432,7 @@ For example the following document will not pass validation.
14191432
* Let {fieldName} be the name of {fieldDefinition}.
14201433
* Let {field} be the input field in {fields} named {fieldName}
14211434
* {field} must exist.
1435+
* {field} must not be deprecated.
14221436
* Let {value} be the value of {field}.
14231437
* {value} must not be the {null} literal.
14241438

@@ -1429,6 +1443,15 @@ arguments, an input object may have required fields. An input field is required
14291443
if it has a non-null type and does not have a default value. Otherwise, the
14301444
input object field is optional.
14311445

1446+
A required input object field must not be marked as deprecated.
1447+
1448+
```graphql counter-example
1449+
input Point {
1450+
x: Int!
1451+
y: Int!
1452+
z: Int! @deprecated(reason: "Northward, not upward")
1453+
}
1454+
```
14321455

14331456
## Directives
14341457

0 commit comments

Comments
 (0)