Skip to content

Commit ba78f00

Browse files
fotoetienneIvanGoncharov
authored andcommitted
Add validation for @deprecated on required arguments (#917)
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 23f175c commit ba78f00

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

spec/Section 3 -- Type System.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,23 @@ type ExampleType {
20732073
}
20742074
```
20752075

2076+
The `@deprecated` directive must not appear on required (non-null without a
2077+
default) arguments or input object field definitions. Deprecated arguments and
2078+
fields are excluded by default in introspection, and deprecating required
2079+
arguments or input fields could create confusion for clients.
2080+
2081+
```graphql counter-example
2082+
type ExampleType {
2083+
invalidField(
2084+
newArg: String
2085+
oldArg: String! @deprecated(reason: "Use `newArg`.")
2086+
): String
2087+
}
2088+
```
2089+
2090+
A required argument or input field should first be made optional by either
2091+
changing the type to nullable or adding a default value.
2092+
20762093
### @specifiedBy
20772094

20782095
```graphql

spec/Section 5 -- Validation.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ invalid.
736736
- Let {argumentName} be the name of {argumentDefinition}.
737737
- Let {argument} be the argument in {arguments} named {argumentName}
738738
- {argument} must exist.
739+
- {argument} must not be deprecated.
739740
- Let {value} be the value of {argument}.
740741
- {value} must not be the {null} literal.
741742

@@ -783,6 +784,18 @@ fragment missingRequiredArg on Arguments {
783784
}
784785
```
785786

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

788801
### Fragment Declarations
@@ -1396,6 +1409,7 @@ For example the following document will not pass validation.
13961409
- Let {fieldName} be the name of {fieldDefinition}.
13971410
- Let {field} be the input field in {fields} named {fieldName}
13981411
- {field} must exist.
1412+
- {field} must not be deprecated.
13991413
- Let {value} be the value of {field}.
14001414
- {value} must not be the {null} literal.
14011415

@@ -1406,6 +1420,16 @@ arguments, an input object may have required fields. An input field is required
14061420
if it has a non-null type and does not have a default value. Otherwise, the
14071421
input object field is optional.
14081422

1423+
A required input object field must not be marked as deprecated.
1424+
1425+
```graphql counter-example
1426+
input Point {
1427+
x: Int!
1428+
y: Int!
1429+
z: Int! @deprecated(reason: "Northward, not upward")
1430+
}
1431+
```
1432+
14091433
## Directives
14101434

14111435
### Directives Are Defined

0 commit comments

Comments
 (0)