Skip to content

Commit 64db57e

Browse files
committed
Fix includeDeprecated arg type
1 parent a334e3a commit 64db57e

File tree

2 files changed

+80
-65
lines changed

2 files changed

+80
-65
lines changed

juniper/src/schema/schema.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,14 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
218218
}
219219
}
220220

221-
fn fields(
222-
&self,
223-
#[graphql(default = false)] include_deprecated: Option<bool>,
224-
) -> Option<Vec<&Field<S>>> {
221+
fn fields(&self, #[graphql(default)] include_deprecated: bool) -> Option<Vec<&Field<S>>> {
225222
match self {
226223
Self::Concrete(t) => match t {
227224
MetaType::Interface(InterfaceMeta { fields, .. })
228225
| MetaType::Object(ObjectMeta { fields, .. }) => Some(
229226
fields
230227
.iter()
231-
.filter(|f| {
232-
include_deprecated.unwrap_or_default()
233-
|| !f.deprecation_status.is_deprecated()
234-
})
228+
.filter(|f| include_deprecated || !f.deprecation_status.is_deprecated())
235229
.filter(|f| !f.name.starts_with("__"))
236230
.collect(),
237231
),
@@ -324,19 +318,13 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
324318
}
325319
}
326320

327-
fn enum_values(
328-
&self,
329-
#[graphql(default = false)] include_deprecated: Option<bool>,
330-
) -> Option<Vec<&EnumValue>> {
321+
fn enum_values(&self, #[graphql(default)] include_deprecated: bool) -> Option<Vec<&EnumValue>> {
331322
match self {
332323
Self::Concrete(t) => match t {
333324
MetaType::Enum(EnumMeta { values, .. }) => Some(
334325
values
335326
.iter()
336-
.filter(|f| {
337-
include_deprecated.unwrap_or_default()
338-
|| !f.deprecation_status.is_deprecated()
339-
})
327+
.filter(|f| include_deprecated || !f.deprecation_status.is_deprecated())
340328
.collect(),
341329
),
342330
MetaType::InputObject(..)
@@ -354,17 +342,14 @@ impl<'a, S: ScalarValue + 'a> TypeType<'a, S> {
354342

355343
fn input_fields(
356344
&self,
357-
#[graphql(default = false)] include_deprecated: Option<bool>,
345+
#[graphql(default)] include_deprecated: bool,
358346
) -> Option<Vec<&Argument<S>>> {
359347
match self {
360348
Self::Concrete(t) => match t {
361349
MetaType::InputObject(InputObjectMeta { input_fields, .. }) => Some(
362350
input_fields
363351
.iter()
364-
.filter(|f| {
365-
include_deprecated.unwrap_or_default()
366-
|| !f.deprecation_status.is_deprecated()
367-
})
352+
.filter(|f| include_deprecated || !f.deprecation_status.is_deprecated())
368353
.collect(),
369354
),
370355
MetaType::Enum(..)
@@ -423,15 +408,10 @@ impl<S: ScalarValue> Field<S> {
423408
self.description.as_ref()
424409
}
425410

426-
fn args(
427-
&self,
428-
#[graphql(default = false)] include_deprecated: Option<bool>,
429-
) -> Vec<&Argument<S>> {
411+
fn args(&self, #[graphql(default)] include_deprecated: bool) -> Vec<&Argument<S>> {
430412
self.arguments.as_ref().map_or_else(Vec::new, |args| {
431413
args.iter()
432-
.filter(|a| {
433-
include_deprecated.unwrap_or_default() || !a.deprecation_status.is_deprecated()
434-
})
414+
.filter(|a| include_deprecated || !a.deprecation_status.is_deprecated())
435415
.collect()
436416
})
437417
}
@@ -532,15 +512,10 @@ impl<S: ScalarValue> DirectiveType<S> {
532512
&self.locations
533513
}
534514

535-
fn args(
536-
&self,
537-
#[graphql(default = false)] include_deprecated: Option<bool>,
538-
) -> Vec<&Argument<S>> {
515+
fn args(&self, #[graphql(default)] include_deprecated: bool) -> Vec<&Argument<S>> {
539516
self.arguments
540517
.iter()
541-
.filter(|a| {
542-
include_deprecated.unwrap_or_default() || !a.deprecation_status.is_deprecated()
543-
})
518+
.filter(|a| include_deprecated || !a.deprecation_status.is_deprecated())
544519
.collect()
545520
}
546521

juniper/src/tests/schema_introspection.rs

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -745,9 +745,13 @@ pub(crate) fn schema_introspection_result() -> Value {
745745
"name": "includeDeprecated",
746746
"description": null,
747747
"type": {
748-
"kind": "SCALAR",
749-
"name": "Boolean",
750-
"ofType": null
748+
"kind": "NON_NULL",
749+
"name": null,
750+
"ofType": {
751+
"kind": "SCALAR",
752+
"name": "Boolean",
753+
"ofType": null
754+
}
751755
},
752756
"defaultValue": "false",
753757
"isDeprecated": false,
@@ -940,9 +944,13 @@ pub(crate) fn schema_introspection_result() -> Value {
940944
"name": "includeDeprecated",
941945
"description": null,
942946
"type": {
943-
"kind": "SCALAR",
944-
"name": "Boolean",
945-
"ofType": null
947+
"kind": "NON_NULL",
948+
"name": null,
949+
"ofType": {
950+
"kind": "SCALAR",
951+
"name": "Boolean",
952+
"ofType": null
953+
}
946954
},
947955
"defaultValue": "false",
948956
"isDeprecated": false,
@@ -1296,9 +1304,13 @@ pub(crate) fn schema_introspection_result() -> Value {
12961304
"name": "includeDeprecated",
12971305
"description": null,
12981306
"type": {
1299-
"kind": "SCALAR",
1300-
"name": "Boolean",
1301-
"ofType": null
1307+
"kind": "NON_NULL",
1308+
"name": null,
1309+
"ofType": {
1310+
"kind": "SCALAR",
1311+
"name": "Boolean",
1312+
"ofType": null
1313+
}
13021314
},
13031315
"defaultValue": "false",
13041316
"isDeprecated": false,
@@ -1369,9 +1381,13 @@ pub(crate) fn schema_introspection_result() -> Value {
13691381
"name": "includeDeprecated",
13701382
"description": null,
13711383
"type": {
1372-
"kind": "SCALAR",
1373-
"name": "Boolean",
1374-
"ofType": null
1384+
"kind": "NON_NULL",
1385+
"name": null,
1386+
"ofType": {
1387+
"kind": "SCALAR",
1388+
"name": "Boolean",
1389+
"ofType": null
1390+
}
13751391
},
13761392
"defaultValue": "false",
13771393
"isDeprecated": false,
@@ -1402,9 +1418,13 @@ pub(crate) fn schema_introspection_result() -> Value {
14021418
"name": "includeDeprecated",
14031419
"description": null,
14041420
"type": {
1405-
"kind": "SCALAR",
1406-
"name": "Boolean",
1407-
"ofType": null
1421+
"kind": "NON_NULL",
1422+
"name": null,
1423+
"ofType": {
1424+
"kind": "SCALAR",
1425+
"name": "Boolean",
1426+
"ofType": null
1427+
}
14081428
},
14091429
"defaultValue": "false",
14101430
"isDeprecated": false,
@@ -2252,9 +2272,13 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
22522272
{
22532273
"name": "includeDeprecated",
22542274
"type": {
2255-
"kind": "SCALAR",
2256-
"name": "Boolean",
2257-
"ofType": null
2275+
"kind": "NON_NULL",
2276+
"name": null,
2277+
"ofType": {
2278+
"kind": "SCALAR",
2279+
"name": "Boolean",
2280+
"ofType": null
2281+
}
22582282
},
22592283
"defaultValue": "false",
22602284
"isDeprecated": false,
@@ -2434,9 +2458,13 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
24342458
{
24352459
"name": "includeDeprecated",
24362460
"type": {
2437-
"kind": "SCALAR",
2438-
"name": "Boolean",
2439-
"ofType": null
2461+
"kind": "NON_NULL",
2462+
"name": null,
2463+
"ofType": {
2464+
"kind": "SCALAR",
2465+
"name": "Boolean",
2466+
"ofType": null
2467+
}
24402468
},
24412469
"defaultValue": "false",
24422470
"isDeprecated": false,
@@ -2766,9 +2794,13 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
27662794
{
27672795
"name": "includeDeprecated",
27682796
"type": {
2769-
"kind": "SCALAR",
2770-
"name": "Boolean",
2771-
"ofType": null
2797+
"kind": "NON_NULL",
2798+
"name": null,
2799+
"ofType": {
2800+
"kind": "SCALAR",
2801+
"name": "Boolean",
2802+
"ofType": null
2803+
}
27722804
},
27732805
"defaultValue": "false",
27742806
"isDeprecated": false,
@@ -2835,9 +2867,13 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
28352867
{
28362868
"name": "includeDeprecated",
28372869
"type": {
2838-
"kind": "SCALAR",
2839-
"name": "Boolean",
2840-
"ofType": null
2870+
"kind": "NON_NULL",
2871+
"name": null,
2872+
"ofType": {
2873+
"kind": "SCALAR",
2874+
"name": "Boolean",
2875+
"ofType": null
2876+
}
28412877
},
28422878
"defaultValue": "false",
28432879
"isDeprecated": false,
@@ -2866,9 +2902,13 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
28662902
{
28672903
"name": "includeDeprecated",
28682904
"type": {
2869-
"kind": "SCALAR",
2870-
"name": "Boolean",
2871-
"ofType": null
2905+
"kind": "NON_NULL",
2906+
"name": null,
2907+
"ofType": {
2908+
"kind": "SCALAR",
2909+
"name": "Boolean",
2910+
"ofType": null
2911+
}
28722912
},
28732913
"defaultValue": "false",
28742914
"isDeprecated": false,

0 commit comments

Comments
 (0)