Skip to content

Commit 6911cb2

Browse files
committed
Cover arguments in Book
1 parent 0f98c45 commit 6911cb2

File tree

5 files changed

+40
-19
lines changed

5 files changed

+40
-19
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/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

0 commit comments

Comments
 (0)