Skip to content

Commit d9e209a

Browse files
authored
Add @deprecated directive (#1008)
1 parent f504da6 commit d9e209a

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

juniper/src/schema/model.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,14 @@ pub enum DirectiveLocation {
8585
Scalar,
8686
#[graphql(name = "FRAGMENT_DEFINITION")]
8787
FragmentDefinition,
88+
#[graphql(name = "FIELD_DEFINITION")]
89+
FieldDefinition,
8890
#[graphql(name = "FRAGMENT_SPREAD")]
8991
FragmentSpread,
9092
#[graphql(name = "INLINE_FRAGMENT")]
9193
InlineFragment,
94+
#[graphql(name = "ENUM_VALUE")]
95+
EnumValue,
9296
}
9397

9498
impl<'a, QueryT, MutationT, SubscriptionT>
@@ -214,6 +218,10 @@ impl<'a, S> SchemaType<'a, S> {
214218
"include".to_owned(),
215219
DirectiveType::new_include(&mut registry),
216220
);
221+
directives.insert(
222+
"deprecated".to_owned(),
223+
DirectiveType::new_deprecated(&mut registry),
224+
);
217225
directives.insert(
218226
"specifiedBy".to_owned(),
219227
DirectiveType::new_specified_by(&mut registry),
@@ -545,6 +553,21 @@ where
545553
)
546554
}
547555

556+
fn new_deprecated(registry: &mut Registry<'a, S>) -> DirectiveType<'a, S>
557+
where
558+
S: ScalarValue,
559+
{
560+
Self::new(
561+
"deprecated",
562+
&[
563+
DirectiveLocation::FieldDefinition,
564+
DirectiveLocation::EnumValue,
565+
],
566+
&[registry.arg::<String>("reason", &())],
567+
false,
568+
)
569+
}
570+
548571
fn new_specified_by(registry: &mut Registry<'a, S>) -> DirectiveType<'a, S>
549572
where
550573
S: ScalarValue,
@@ -570,10 +593,12 @@ impl fmt::Display for DirectiveLocation {
570593
DirectiveLocation::Mutation => "mutation",
571594
DirectiveLocation::Subscription => "subscription",
572595
DirectiveLocation::Field => "field",
596+
DirectiveLocation::FieldDefinition => "field definition",
573597
DirectiveLocation::FragmentDefinition => "fragment definition",
574598
DirectiveLocation::FragmentSpread => "fragment spread",
575599
DirectiveLocation::InlineFragment => "inline fragment",
576600
DirectiveLocation::Scalar => "scalar",
601+
DirectiveLocation::EnumValue => "enum value",
577602
})
578603
}
579604
}

juniper/src/tests/introspection_tests.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ async fn test_introspection_directives() {
208208
"INLINE_FRAGMENT",
209209
],
210210
},
211+
{
212+
"name": "deprecated",
213+
"locations": [
214+
"FIELD_DEFINITION",
215+
"ENUM_VALUE",
216+
],
217+
},
211218
{
212219
"name": "specifiedBy",
213220
"locations": [

juniper/src/tests/schema_introspection.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,12 @@ pub(crate) fn schema_introspection_result() -> Value {
10501050
"isDeprecated": false,
10511051
"deprecationReason": null
10521052
},
1053+
{
1054+
"name": "FIELD_DEFINITION",
1055+
"description": null,
1056+
"isDeprecated": false,
1057+
"deprecationReason": null
1058+
},
10531059
{
10541060
"name": "FRAGMENT_SPREAD",
10551061
"description": null,
@@ -1067,6 +1073,12 @@ pub(crate) fn schema_introspection_result() -> Value {
10671073
"description": null,
10681074
"isDeprecated": false,
10691075
"deprecationReason": null
1076+
},
1077+
{
1078+
"name": "ENUM_VALUE",
1079+
"description": null,
1080+
"isDeprecated": false,
1081+
"deprecationReason": null
10701082
}
10711083
],
10721084
"possibleTypes": null
@@ -1376,6 +1388,31 @@ pub(crate) fn schema_introspection_result() -> Value {
13761388
}
13771389
]
13781390
},
1391+
{
1392+
"name": "deprecated",
1393+
"description": null,
1394+
"isRepeatable": false,
1395+
"locations": [
1396+
"FIELD_DEFINITION",
1397+
"ENUM_VALUE"
1398+
],
1399+
"args": [
1400+
{
1401+
"name": "reason",
1402+
"description": null,
1403+
"type": {
1404+
"kind": "NON_NULL",
1405+
"name": null,
1406+
"ofType": {
1407+
"kind": "SCALAR",
1408+
"name": "String",
1409+
"ofType": null
1410+
}
1411+
},
1412+
"defaultValue": null
1413+
}
1414+
]
1415+
},
13791416
{
13801417
"name": "specifiedBy",
13811418
"description": null,
@@ -2345,6 +2382,11 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
23452382
"isDeprecated": false,
23462383
"deprecationReason": null
23472384
},
2385+
{
2386+
"name": "FIELD_DEFINITION",
2387+
"isDeprecated": false,
2388+
"deprecationReason": null
2389+
},
23482390
{
23492391
"name": "FRAGMENT_SPREAD",
23502392
"isDeprecated": false,
@@ -2359,6 +2401,11 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
23592401
"name": "SCALAR",
23602402
"isDeprecated": false,
23612403
"deprecationReason": null
2404+
},
2405+
{
2406+
"name": "ENUM_VALUE",
2407+
"isDeprecated": false,
2408+
"deprecationReason": null
23622409
}
23632410
],
23642411
"possibleTypes": null
@@ -2650,6 +2697,29 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
26502697
}
26512698
]
26522699
},
2700+
{
2701+
"name": "deprecated",
2702+
"isRepeatable": false,
2703+
"locations": [
2704+
"FIELD_DEFINITION",
2705+
"ENUM_VALUE"
2706+
],
2707+
"args": [
2708+
{
2709+
"name": "reason",
2710+
"type": {
2711+
"kind": "NON_NULL",
2712+
"name": null,
2713+
"ofType": {
2714+
"kind": "SCALAR",
2715+
"name": "String",
2716+
"ofType": null
2717+
}
2718+
},
2719+
"defaultValue": null
2720+
}
2721+
]
2722+
},
26532723
{
26542724
"name": "specifiedBy",
26552725
"isRepeatable": false,

0 commit comments

Comments
 (0)