Skip to content

Commit

Permalink
Add validation for @deprecated on required arguments (#917)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fotoetienne authored and IvanGoncharov committed Jan 9, 2022
1 parent 23f175c commit ba78f00
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,23 @@ type ExampleType {
}
```

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.

```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
Expand Down
24 changes: 24 additions & 0 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ invalid.
- Let {argumentName} be the name of {argumentDefinition}.
- Let {argument} be the argument in {arguments} named {argumentName}
- {argument} must exist.
- {argument} must not be deprecated.
- Let {value} be the value of {argument}.
- {value} must not be the {null} literal.

Expand Down Expand Up @@ -783,6 +784,18 @@ fragment missingRequiredArg on Arguments {
}
```

If an argument is required (non-null without a default value), it must not be
marked as deprecated.

```graphql counter-example
type Query {
"""
This is invalid because the locale argument is both required and deprecated.
"""
myName(locale: String! @deprecated): String
}
```

## Fragments

### Fragment Declarations
Expand Down Expand Up @@ -1396,6 +1409,7 @@ For example the following document will not pass validation.
- Let {fieldName} be the name of {fieldDefinition}.
- Let {field} be the input field in {fields} named {fieldName}
- {field} must exist.
- {field} must not be deprecated.
- Let {value} be the value of {field}.
- {value} must not be the {null} literal.

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

A required input object field must not be marked as deprecated.

```graphql counter-example
input Point {
x: Int!
y: Int!
z: Int! @deprecated(reason: "Northward, not upward")
}
```

## Directives

### Directives Are Defined
Expand Down

0 comments on commit ba78f00

Please sign in to comment.