Skip to content

Add validation for @deprecated on required arguments #917

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

Merged
merged 1 commit into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions spec/Section 3 -- Type System.md
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,22 @@ 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

Expand Down
23 changes: 23 additions & 0 deletions spec/Section 5 -- Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ and 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 @@ -785,6 +786,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 @@ -1419,6 +1432,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 @@ -1429,6 +1443,15 @@ 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

Expand Down