Skip to content

Commit 90ecd03

Browse files
authored
Deprecation of input object fields and arguments (#1348, #864, #1347, graphql/graphql-spec#525, graphql/graphql-spec#805)
- allow `#[graphql(deprecated)]` and `#[deprecated]` attributes on struct fields in `#[derive(GraphQLInputObject)]` macro - allow `#[graphql(deprecated)]` attribute on method arguments in `#[graphql_object]` and `#[graphql_interface]` macros - allow `@deprecated` directive on arguments and input object fields - add `__InputValue.isDeprecated` and `__InputValue.deprecationReason` fields - add `includeDeprecated` argument to `__Type.inputFields`, `__Field.args` and `__Directive.args` fields - make `includeDeprecated` argument of `__Type.fields`, `__Type.enumValues`, `__Type.inputFields`, `__Field.args` and `__Directive.args` fields non-`Null` (graphql/graphql-spec#1142) - add `schema::meta::Argument::deprecation_status` field - make `@deprecated(reason:)` argument non-`Null` (graphql/graphql-spec#1040) Additionally: - add `__Type.isOneOf` field (graphql/graphql-spec#825) - add `SCHEMA`, `OBJECT`, `ARGUMENT_DEFINITION`, `INTERFACE`, `UNION`, `ENUM`, `INPUT_OBJECT` and `INPUT_FIELD_DEFINITION` values to `__DirectiveLocation` enum - update canonical introspection query to 16.11.0 version of GraphQL.js - fix incorrect `__Type.specifiedByUrl` field name to `__Type.specifiedByURL` - fix missing `@specifiedBy(url:)` directive in SDL generated by `RootNode::as_sdl()` and `RootNode::as_document()` methods
1 parent 4e3670d commit 90ecd03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2077
-696
lines changed

book/src/types/enums.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ enum Episode {
7575

7676
### Documentation and deprecation
7777

78-
Just like when [defining GraphQL objects](objects/index.md#documentation), the [GraphQL enum][0] type and its values could be [documented][4] and [deprecated][5] via `#[graphql(description = "...")]` and `#[graphql(deprecated = "...")]`/[`#[deprecated]`][13] attributes:
78+
Just like when [defining GraphQL objects](objects/index.md#documentation), the [GraphQL enum][0] type and its values could be [documented][4] and [deprecated][9] via `#[graphql(description = "...")]` and `#[graphql(deprecated = "...")]`/[`#[deprecated]`][13] attributes:
7979
```rust
8080
# extern crate juniper;
8181
# use juniper::GraphQLEnum;
@@ -105,7 +105,7 @@ enum StarWarsEpisode {
105105
#
106106
# fn main() {}
107107
```
108-
> **NOTE**: Only [GraphQL object][6]/[interface][7] fields and [GraphQL enum][0] values can be [deprecated][5].
108+
> **NOTE**: Only [GraphQL object][6]/[interface][7]/[input object][8] fields, [arguments][5] and [GraphQL enum][0] values can be [deprecated][9].
109109
110110

111111
### Ignoring
@@ -145,7 +145,9 @@ enum Episode<T> {
145145
[2]: https://docs.rs/juniper/0.17.0/juniper/derive.GraphQLEnum.html
146146
[3]: https://doc.rust-lang.org/reference/items/enumerations.html
147147
[4]: https://spec.graphql.org/October2021#sec-Descriptions
148-
[5]: https://spec.graphql.org/October2021#sec--deprecated
148+
[5]: https://spec.graphql.org/October2021#sec-Language.Arguments
149149
[6]: https://spec.graphql.org/October2021#sec-Objects
150150
[7]: https://spec.graphql.org/October2021#sec-Interfaces
151-
[13]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
151+
[8]: https://spec.graphql.org/October2021#sec-Input-Objects
152+
[9]: https://spec.graphql.org/October2021#sec--deprecated
153+
[13]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute

book/src/types/input_objects.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ struct Person {
8484
> **TIP**: Supported policies are: `SCREAMING_SNAKE_CASE`, `camelCase` and `none` (disables any renaming).
8585
8686

87-
### Documentation
87+
### Documentation and deprecation
8888

89-
Similarly, [GraphQL descriptions][7] may be provided by either using [Rust doc comments][6] or with the `#[graphql(description = "...")]` attribute:
89+
Similarly, [GraphQL input fields][1] may also be [documented][7] and [deprecated][9] via `#[graphql(description = "...")]` and `#[graphql(deprecated = "...")]`/[`#[deprecated]`][13] attributes:
9090
```rust
9191
# extern crate juniper;
9292
# use juniper::GraphQLInputObject;
@@ -102,12 +102,20 @@ struct Person {
102102

103103
/// This doc comment is visible in both Rust API docs and GraphQL schema
104104
/// descriptions.
105+
// Only `Null`able input fields or non-`Null` input fields with default values
106+
// can be deprecated.
107+
#[graphql(default, deprecated = "Just because.")]
105108
age: i32,
109+
110+
// If no explicit deprecation reason is provided,
111+
// then the default "No longer supported" one is used.
112+
#[deprecated]
113+
another: Option<f64>, // has no description in GraphQL schema
106114
}
107115
#
108116
# fn main() {}
109117
```
110-
> **NOTE**: As of [October 2021 GraphQL specification][spec], [GraphQL input object][0]'s fields **cannot be** [deprecated][9].
118+
> **NOTE**: Only [GraphQL input object][0]/[object][8]/[interface][11] fields, [arguments][5] and [GraphQL enum][10] values can be [deprecated][9].
111119
112120

113121
### Ignoring
@@ -150,14 +158,17 @@ struct Point2D {
150158
[Juniper]: https://docs.rs/juniper
151159
[Rust]: https://www.rust-lang.org
152160
[struct]: https://doc.rust-lang.org/reference/items/structs.html
153-
[spec]: https://spec.graphql.org/October2021
154161

155162
[0]: https://spec.graphql.org/October2021#sec-Input-Objects
163+
[1]: https://spec.graphql.org/October2021#InputFieldsDefinition
156164
[2]: https://docs.rs/juniper/0.17.0/juniper/derive.GraphQLInputObject.html
157165
[4]: https://spec.graphql.org/October2021#sec-Language.Fields
158166
[5]: https://spec.graphql.org/October2021#sec-Language.Arguments
159167
[6]: https://doc.rust-lang.org/reference/comments.html#doc-comments
160168
[7]: https://spec.graphql.org/October2021#sec-Descriptions
169+
[8]: https://spec.graphql.org/October2021#sec-Objects
161170
[9]: https://spec.graphql.org/October2021#sec--deprecated
162171
[10]: https://spec.graphql.org/October2021#sec-Enums
172+
[11]: https://spec.graphql.org/October2021#sec-Interfaces
163173
[12]: https://spec.graphql.org/October2021#sec-Scalars
174+
[13]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute

book/src/types/interfaces.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ trait Person {
317317

318318
### Documentation and deprecation
319319

320-
Similarly, [GraphQL fields][4] of [interfaces][0] may also be [documented][7] and [deprecated][9] via `#[graphql(description = "...")]` and `#[graphql(deprecated = "...")]`/[`#[deprecated]`][13] attributes:
320+
Similarly, [GraphQL fields][4] (and their [arguments][5]) of [interfaces][0] may also be [documented][7] and [deprecated][9] via `#[graphql(description = "...")]` and `#[graphql(deprecated = "...")]`/[`#[deprecated]`][13] attributes:
321321
```rust
322322
# extern crate juniper;
323323
# use juniper::graphql_interface;
@@ -340,16 +340,24 @@ trait Person {
340340
/// This doc comment is visible in both Rust API docs and GraphQL schema
341341
/// descriptions.
342342
#[graphql(deprecated = "Just because.")]
343-
fn deprecated_graphql() -> bool;
343+
fn deprecated_graphql(
344+
// Only `Null`able arguments or non-`Null` arguments with default values
345+
// can be deprecated.
346+
#[graphql(default, deprecated = "No need.")] arg: bool,
347+
) -> bool;
344348

345349
// Standard Rust's `#[deprecated]` attribute works too!
346350
#[deprecated(note = "Reason is optional, btw!")]
347-
fn deprecated_standard() -> bool; // has no description in GraphQL schema
351+
fn deprecated_standard( // has no description in GraphQL schema
352+
// If no explicit deprecation reason is provided,
353+
// then the default "No longer supported" one is used.
354+
#[graphql(deprecated)] arg: Option<bool>,
355+
) -> bool;
348356
}
349357
#
350358
# fn main() {}
351359
```
352-
> **NOTE**: Only [GraphQL interface][0]/[object][10] fields and [GraphQL enum][11] values can be [deprecated][9].
360+
> **NOTE**: Only [GraphQL interface][0]/[object][10]/[input object][8] fields, [arguments][5] and [GraphQL enum][11] values can be [deprecated][9].
353361
354362

355363
### Ignoring
@@ -403,6 +411,7 @@ trait Person {
403411
[5]: https://spec.graphql.org/October2021#sec-Language.Arguments
404412
[6]: https://spec.graphql.org/October2021#sec-Non-Null
405413
[7]: https://spec.graphql.org/October2021#sec-Descriptions
414+
[8]: https://spec.graphql.org/October2021#sec-Input-Objects
406415
[9]: https://spec.graphql.org/October2021#sec--deprecated
407416
[10]: https://spec.graphql.org/October2021#sec-Objects
408417
[11]: https://spec.graphql.org/October2021#sec-Enums

book/src/types/objects/complex_fields.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Person {
116116

117117
### Documentation and deprecation
118118

119-
Similarly, [GraphQL fields][4] may also be [documented][7] and [deprecated][9] via `#[graphql(description = "...")]` and `#[graphql(deprecated = "...")]`/[`#[deprecated]`][13] attributes:
119+
Similarly, [GraphQL fields][4] (and their [arguments][5]) may also be [documented][7] and [deprecated][9] via `#[graphql(description = "...")]` and `#[graphql(deprecated = "...")]`/[`#[deprecated]`][13] attributes:
120120
```rust
121121
# extern crate juniper;
122122
# use juniper::graphql_object;
@@ -145,20 +145,28 @@ impl Person {
145145
/// This doc comment is visible in both Rust API docs and GraphQL schema
146146
/// descriptions.
147147
#[graphql(deprecated = "Just because.")]
148-
fn deprecated_graphql() -> bool {
148+
fn deprecated_graphql(
149+
// Only `Null`able arguments or non-`Null` arguments with default values
150+
// can be deprecated.
151+
#[graphql(default, deprecated = "No need.")] arg: bool,
152+
) -> bool {
149153
true
150154
}
151155

152156
// Standard Rust's `#[deprecated]` attribute works too!
153157
#[deprecated(note = "Reason is optional, btw!")]
154-
fn deprecated_standard() -> bool { // has no description in GraphQL schema
158+
fn deprecated_standard( // has no description in GraphQL schema
159+
// If no explicit deprecation reason is provided,
160+
// then the default "No longer supported" one is used.
161+
#[graphql(deprecated)] arg: Option<bool>,
162+
) -> bool {
155163
false
156164
}
157165
}
158166
#
159167
# fn main() {}
160168
```
161-
> **NOTE**: Only [GraphQL object][0]/[interface][11] fields and [GraphQL enum][10] values can be [deprecated][9].
169+
> **NOTE**: Only [GraphQL object][0]/[interface][11]/[input object][8] fields, [arguments][5] and [GraphQL enum][10] values can be [deprecated][9].
162170
163171

164172
### Ignoring
@@ -223,6 +231,7 @@ impl Person {
223231
[5]: https://spec.graphql.org/October2021#sec-Language.Arguments
224232
[6]: https://doc.rust-lang.org/reference/items/implementations.html#inherent-implementations
225233
[7]: https://spec.graphql.org/October2021#sec-Descriptions
234+
[8]: https://spec.graphql.org/October2021#sec-Input-Objects
226235
[9]: https://spec.graphql.org/October2021#sec--deprecated
227236
[10]: https://spec.graphql.org/October2021#sec-Enums
228237
[11]: https://spec.graphql.org/October2021#sec-Interfaces

book/src/types/objects/error/field.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ impl Example {
3737
# fn main() {}
3838
```
3939

40-
[`FieldResult<T>`][21] is an alias for [`Result<T, FieldError>`][22], which is the [error type][1] all fallible [fields][6] must return. By using the [`?` operator][14], any type that implements the [`Display` trait][15] (which most of the error types out there do) can be automatically converted into a [`FieldError`][22].
40+
[`FieldResult<T>`][21] is an alias for [`Result<T, FieldError>`][22], which is the [error type][1] all fallible [fields][6] must return. By using the [`?` operator][14], any type that implements the [`Display` trait][19] (which most of the error types out there do) can be automatically converted into a [`FieldError`][22].
4141

4242
> **TIP**: If a custom conversion into a [`FieldError`][22] is needed (to [fill up `extensions`][2], for example), the [`IntoFieldError` trait][23] should be implemented.
4343
44-
> **NOTE**: [`FieldError`][22]s are [GraphQL field errors][1] and are [not visible][9] in a [GraphQL schema][8] in any way.
44+
> **NOTE**: [`FieldError`][22]s are [GraphQL field errors][1] and are [not visible][15] in a [GraphQL schema][8] in any way.
4545
4646

4747

@@ -172,12 +172,12 @@ And the specified structured error information will be included into the [error'
172172
[6]: https://spec.graphql.org/October2021#sec-Language.Fields
173173
[7]: https://spec.graphql.org/October2021#sec-Response
174174
[8]: https://graphql.org/learn/schema
175-
[9]: https://spec.graphql.org/October2021#sec-Introspection
176175
[11]: https://doc.rust-lang.org/book/ch09-00-error-handling.html
177176
[12]: https://doc.rust-lang.org/stable/std/result/enum.Result.html
178177
[13]: https://doc.rust-lang.org/stable/std/macro.panic.html
179178
[14]: https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
180-
[15]: https://doc.rust-lang.org/stable/std/fmt/trait.Display.html
179+
[15]: https://spec.graphql.org/October2021#sec-Introspection
180+
[19]: https://doc.rust-lang.org/stable/std/fmt/trait.Display.html
181181
[21]: https://docs.rs/juniper/0.17.0/juniper/executor/type.FieldResult.html
182182
[22]: https://docs.rs/juniper/0.17.0/juniper/executor/struct.FieldError.html
183183
[23]: https://docs.rs/juniper/0.17.0/juniper/executor/trait.IntoFieldError.html

book/src/types/objects/index.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This creates a [GraphQL object][0] type called `Person`, with two fields: `name`
3434

3535
### Documentation
3636

37-
We should take advantage of the fact that [GraphQL] is [self-documenting][5] and add descriptions to the defined [GraphQL object][0] type and its fields. [Juniper] will automatically use associated [Rust doc comments][6] as [GraphQL descriptions][7]:
37+
We should take advantage of the fact that [GraphQL] is [self-documenting][15] and add descriptions to the defined [GraphQL object][0] type and its fields. [Juniper] will automatically use associated [Rust doc comments][6] as [GraphQL descriptions][7]:
3838
```rust
3939
# extern crate juniper;
4040
# use juniper::GraphQLObject;
@@ -145,7 +145,7 @@ struct Person {
145145
#
146146
# fn main() {}
147147
```
148-
> **NOTE**: Only [GraphQL object][0]/[interface][11] fields and [GraphQL enum][10] values can be [deprecated][9].
148+
> **NOTE**: Only [GraphQL object][0]/[interface][11]/[input object][8] fields, [arguments][5] and [GraphQL enum][10] values can be [deprecated][9].
149149
150150

151151
### Ignoring
@@ -216,7 +216,7 @@ Because `Person` is a valid [GraphQL] type, we can have a `Vec<Person>` in a [st
216216
[2]: https://docs.rs/juniper/0.17.0/juniper/derive.GraphQLObject.html
217217
[3]: https://docs.rs/juniper/0.17.0/juniper/attr.graphql_object.html
218218
[4]: https://spec.graphql.org/October2021#sec-Non-Null
219-
[5]: https://spec.graphql.org/October2021#sec-Introspection
219+
[5]: https://spec.graphql.org/October2021#sec-Language.Arguments
220220
[6]: https://doc.rust-lang.org/reference/comments.html#doc-comments
221221
[7]: https://spec.graphql.org/October2021#sec-Descriptions
222222
[8]: https://spec.graphql.org/October2021#sec-Input-Objects
@@ -226,3 +226,4 @@ Because `Person` is a valid [GraphQL] type, we can have a `Vec<Person>` in a [st
226226
[12]: https://spec.graphql.org/October2021#sec-List
227227
[13]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
228228
[14]: https://spec.graphql.org/October2021#sel-EAFdRDHAAEJDAoBxzT
229+
[15]: https://spec.graphql.org/October2021#sec-Introspection

juniper/CHANGELOG.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,51 @@ All user visible changes to `juniper` crate will be documented in this file. Thi
66

77

88

9+
## main
10+
11+
[Diff](/../../compare/juniper-v0.17.0...main) | [Milestone](/../../milestone/9)
12+
13+
### BC Breaks
14+
15+
- [September 2025] GraphQL spec: ([#1347])
16+
- Made `includeDeprecated` argument of `__Type.fields`, `__Type.enumValues`, `__Type.inputFields`, `__Field.args` and `__Directive.args` fields non-`Null`. ([#1348], [graphql/graphql-spec#1142])
17+
- Made `@deprecated(reason:)` argument non-`Null`. ([#1348], [graphql/graphql-spec#1040])
18+
19+
### Added
20+
21+
- [September 2025] GraphQL spec: ([#1347])
22+
- `__Type.isOneOf` field. ([#1348], [graphql/graphql-spec#825])
23+
- `SCHEMA`, `OBJECT`, `ARGUMENT_DEFINITION`, `INTERFACE`, `UNION`, `ENUM`, `INPUT_OBJECT` and `INPUT_FIELD_DEFINITION` values to `__DirectiveLocation` enum. ([#1348])
24+
- Arguments and input object fields deprecation: ([#1348], [#864], [graphql/graphql-spec#525], [graphql/graphql-spec#805])
25+
- Placing `#[graphql(deprecated)]` and `#[deprecated]` attributes on struct fields in `#[derive(GraphQLInputObject)]` macro.
26+
- Placing `#[graphql(deprecated)]` attribute on method arguments in `#[graphql_object]` and `#[graphql_interface]` macros.
27+
- Placing `@deprecated` directive on arguments and input object fields.
28+
- `includeDeprecated` argument to `__Type.inputFields`, `__Field.args` and `__Directive.args` fields.
29+
- `__InputValue.isDeprecated` and `__InputValue.deprecationReason` fields.
30+
- `schema::meta::Argument::deprecation_status` field.
31+
32+
### Changed
33+
34+
- [September 2025] GraphQL spec: ([#1347])
35+
- Canonical introspection query to [16.11.0 version of GraphQL.js](https://github.com/graphql/graphql-js/blob/v16.11.0/src/utilities/getIntrospectionQuery.ts#L75). ([#1348])
36+
37+
### Fixed
38+
39+
- Incorrect `__Type.specifiedByUrl` field to `__Type.specifiedByURL`. ([#1348])
40+
- Missing `@specifiedBy(url:)` directive in [SDL] generated by `RootNode::as_sdl()` and `RootNode::as_document()` methods. ([#1348])
41+
42+
[#864]: /../../issues/864
43+
[#1347]: /../../issues/1347
44+
[#1348]: /../../pull/1348
45+
[graphql/graphql-spec#525]: https://github.com/graphql/graphql-spec/pull/525
46+
[graphql/graphql-spec#805]: https://github.com/graphql/graphql-spec/pull/805
47+
[graphql/graphql-spec#825]: https://github.com/graphql/graphql-spec/pull/825
48+
[graphql/graphql-spec#1040]: https://github.com/graphql/graphql-spec/pull/1040
49+
[graphql/graphql-spec#1142]: https://github.com/graphql/graphql-spec/pull/1142
50+
51+
52+
53+
954
## [0.17.0] · 2025-09-08
1055
[0.17.0]: /../../tree/juniper-v0.17.0/juniper
1156

@@ -398,3 +443,5 @@ See [old CHANGELOG](/../../blob/juniper-v0.15.12/juniper/CHANGELOG.md).
398443
[object safety]: https://doc.rust-lang.org/reference/items/traits.html#object-safety
399444
[orphan rules]: https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
400445
[Semantic Versioning 2.0.0]: https://semver.org
446+
[September 2025]: https://spec.graphql.org/September2025
447+
[SDL]: https://graphql.org/learn/schema#type-language

0 commit comments

Comments
 (0)