Add @deprecated
directive (#1008)
This commit is contained in:
parent
f504da6d15
commit
d9e209a19d
3 changed files with 102 additions and 0 deletions
|
@ -85,10 +85,14 @@ pub enum DirectiveLocation {
|
|||
Scalar,
|
||||
#[graphql(name = "FRAGMENT_DEFINITION")]
|
||||
FragmentDefinition,
|
||||
#[graphql(name = "FIELD_DEFINITION")]
|
||||
FieldDefinition,
|
||||
#[graphql(name = "FRAGMENT_SPREAD")]
|
||||
FragmentSpread,
|
||||
#[graphql(name = "INLINE_FRAGMENT")]
|
||||
InlineFragment,
|
||||
#[graphql(name = "ENUM_VALUE")]
|
||||
EnumValue,
|
||||
}
|
||||
|
||||
impl<'a, QueryT, MutationT, SubscriptionT>
|
||||
|
@ -214,6 +218,10 @@ impl<'a, S> SchemaType<'a, S> {
|
|||
"include".to_owned(),
|
||||
DirectiveType::new_include(&mut registry),
|
||||
);
|
||||
directives.insert(
|
||||
"deprecated".to_owned(),
|
||||
DirectiveType::new_deprecated(&mut registry),
|
||||
);
|
||||
directives.insert(
|
||||
"specifiedBy".to_owned(),
|
||||
DirectiveType::new_specified_by(&mut registry),
|
||||
|
@ -545,6 +553,21 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
fn new_deprecated(registry: &mut Registry<'a, S>) -> DirectiveType<'a, S>
|
||||
where
|
||||
S: ScalarValue,
|
||||
{
|
||||
Self::new(
|
||||
"deprecated",
|
||||
&[
|
||||
DirectiveLocation::FieldDefinition,
|
||||
DirectiveLocation::EnumValue,
|
||||
],
|
||||
&[registry.arg::<String>("reason", &())],
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn new_specified_by(registry: &mut Registry<'a, S>) -> DirectiveType<'a, S>
|
||||
where
|
||||
S: ScalarValue,
|
||||
|
@ -570,10 +593,12 @@ impl fmt::Display for DirectiveLocation {
|
|||
DirectiveLocation::Mutation => "mutation",
|
||||
DirectiveLocation::Subscription => "subscription",
|
||||
DirectiveLocation::Field => "field",
|
||||
DirectiveLocation::FieldDefinition => "field definition",
|
||||
DirectiveLocation::FragmentDefinition => "fragment definition",
|
||||
DirectiveLocation::FragmentSpread => "fragment spread",
|
||||
DirectiveLocation::InlineFragment => "inline fragment",
|
||||
DirectiveLocation::Scalar => "scalar",
|
||||
DirectiveLocation::EnumValue => "enum value",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,6 +208,13 @@ async fn test_introspection_directives() {
|
|||
"INLINE_FRAGMENT",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "deprecated",
|
||||
"locations": [
|
||||
"FIELD_DEFINITION",
|
||||
"ENUM_VALUE",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "specifiedBy",
|
||||
"locations": [
|
||||
|
|
|
@ -1050,6 +1050,12 @@ pub(crate) fn schema_introspection_result() -> Value {
|
|||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "FIELD_DEFINITION",
|
||||
"description": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "FRAGMENT_SPREAD",
|
||||
"description": null,
|
||||
|
@ -1067,6 +1073,12 @@ pub(crate) fn schema_introspection_result() -> Value {
|
|||
"description": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "ENUM_VALUE",
|
||||
"description": null,
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"possibleTypes": null
|
||||
|
@ -1376,6 +1388,31 @@ pub(crate) fn schema_introspection_result() -> Value {
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "deprecated",
|
||||
"description": null,
|
||||
"isRepeatable": false,
|
||||
"locations": [
|
||||
"FIELD_DEFINITION",
|
||||
"ENUM_VALUE"
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "reason",
|
||||
"description": null,
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "specifiedBy",
|
||||
"description": null,
|
||||
|
@ -2345,6 +2382,11 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
|
|||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "FIELD_DEFINITION",
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "FRAGMENT_SPREAD",
|
||||
"isDeprecated": false,
|
||||
|
@ -2359,6 +2401,11 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
|
|||
"name": "SCALAR",
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
},
|
||||
{
|
||||
"name": "ENUM_VALUE",
|
||||
"isDeprecated": false,
|
||||
"deprecationReason": null
|
||||
}
|
||||
],
|
||||
"possibleTypes": null
|
||||
|
@ -2650,6 +2697,29 @@ pub(crate) fn schema_introspection_result_without_descriptions() -> Value {
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "deprecated",
|
||||
"isRepeatable": false,
|
||||
"locations": [
|
||||
"FIELD_DEFINITION",
|
||||
"ENUM_VALUE"
|
||||
],
|
||||
"args": [
|
||||
{
|
||||
"name": "reason",
|
||||
"type": {
|
||||
"kind": "NON_NULL",
|
||||
"name": null,
|
||||
"ofType": {
|
||||
"kind": "SCALAR",
|
||||
"name": "String",
|
||||
"ofType": null
|
||||
}
|
||||
},
|
||||
"defaultValue": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "specifiedBy",
|
||||
"isRepeatable": false,
|
||||
|
|
Loading…
Reference in a new issue