From 313ebd534b74782b6cc9e3db7dc6d1fe2ce94e39 Mon Sep 17 00:00:00 2001 From: pizzacat83 <17941141+pizzacat83@users.noreply.github.com> Date: Sat, 1 Apr 2023 20:12:23 +0900 Subject: [PATCH] support `extend type Foo` --- graphql_client_codegen/src/schema.rs | 6 + .../src/schema/graphql_parser_conversion.rs | 52 +- graphql_client_codegen/src/schema/tests.rs | 1 + .../src/schema/tests/extend_object.rs | 129 ++ .../schema/tests/extend_object_schema.graphql | 11 + .../schema/tests/extend_object_schema.json | 1069 +++++++++++++++++ 6 files changed, 1267 insertions(+), 1 deletion(-) create mode 100644 graphql_client_codegen/src/schema/tests/extend_object.rs create mode 100644 graphql_client_codegen/src/schema/tests/extend_object_schema.graphql create mode 100644 graphql_client_codegen/src/schema/tests/extend_object_schema.json diff --git a/graphql_client_codegen/src/schema.rs b/graphql_client_codegen/src/schema.rs index fc3b5094c..0e0c5fd7b 100644 --- a/graphql_client_codegen/src/schema.rs +++ b/graphql_client_codegen/src/schema.rs @@ -327,6 +327,12 @@ impl Schema { .expect("Schema::get_object") } + pub(crate) fn get_object_mut(&mut self, object_id: ObjectId) -> &mut StoredObject { + self.stored_objects + .get_mut(object_id.0 as usize) + .expect("Schema::get_object_mut") + } + pub(crate) fn get_field(&self, field_id: StoredFieldId) -> &StoredField { self.stored_fields.get(field_id.0).unwrap() } diff --git a/graphql_client_codegen/src/schema/graphql_parser_conversion.rs b/graphql_client_codegen/src/schema/graphql_parser_conversion.rs index fadd9f469..b235e7ae9 100644 --- a/graphql_client_codegen/src/schema/graphql_parser_conversion.rs +++ b/graphql_client_codegen/src/schema/graphql_parser_conversion.rs @@ -1,6 +1,8 @@ use super::{Schema, StoredInputFieldType, TypeId}; use crate::schema::resolve_field_type; -use graphql_parser::schema::{self as parser, Definition, Document, TypeDefinition, UnionType}; +use graphql_parser::schema::{ + self as parser, Definition, Document, TypeDefinition, TypeExtension, UnionType, +}; pub(super) fn build_schema<'doc, T>( mut src: graphql_parser::schema::Document<'doc, T>, @@ -36,6 +38,8 @@ where interfaces_mut(src).for_each(|iface| ingest_interface(schema, iface)); objects_mut(src).for_each(|obj| ingest_object(schema, obj)); + extend_object_type_extensions_mut(src) + .for_each(|ext| ingest_object_type_extension(schema, ext)); inputs_mut(src).for_each(|input| ingest_input(schema, input)); @@ -200,6 +204,40 @@ fn ingest_object<'doc, T>( schema.push_object(object); } +fn ingest_object_type_extension<'doc, T>( + schema: &mut Schema, + ext: &mut graphql_parser::schema::ObjectTypeExtension<'doc, T>, +) where + T: graphql_parser::query::Text<'doc>, +{ + let object_id = schema + .find_type_id(ext.name.as_ref()) + .as_object_id() + .unwrap(); + let mut field_ids = Vec::with_capacity(ext.fields.len()); + + for field in ext.fields.iter_mut() { + let field = super::StoredField { + name: field.name.as_ref().into(), + r#type: resolve_field_type(schema, &field.field_type), + parent: super::StoredFieldParent::Object(object_id), + deprecation: find_deprecation(&field.directives), + }; + + field_ids.push(schema.push_field(field)); + } + + let iface_ids = ext + .implements_interfaces + .iter() + .map(|iface_name| schema.find_interface(iface_name.as_ref())) + .collect::>(); + + let object = schema.get_object_mut(object_id); + object.implements_interfaces.extend(iface_ids); + object.fields.extend(field_ids); +} + fn ingest_scalar<'doc, T>( schema: &mut Schema, scalar: &mut graphql_parser::schema::ScalarType<'doc, T>, @@ -328,6 +366,18 @@ where }) } +fn extend_object_type_extensions_mut<'a, 'doc: 'a, T>( + doc: &'a mut Document<'doc, T>, +) -> impl Iterator> +where + T: graphql_parser::query::Text<'doc>, +{ + doc.definitions.iter_mut().filter_map(|def| match def { + Definition::TypeExtension(TypeExtension::Object(obj)) => Some(obj), + _ => None, + }) +} + fn interfaces_mut<'a, 'doc: 'a, T>( doc: &'a mut Document<'doc, T>, ) -> impl Iterator> diff --git a/graphql_client_codegen/src/schema/tests.rs b/graphql_client_codegen/src/schema/tests.rs index 6a5a51cbc..8735b989f 100644 --- a/graphql_client_codegen/src/schema/tests.rs +++ b/graphql_client_codegen/src/schema/tests.rs @@ -1 +1,2 @@ +mod extend_object; mod github; diff --git a/graphql_client_codegen/src/schema/tests/extend_object.rs b/graphql_client_codegen/src/schema/tests/extend_object.rs new file mode 100644 index 000000000..c3f20fdc0 --- /dev/null +++ b/graphql_client_codegen/src/schema/tests/extend_object.rs @@ -0,0 +1,129 @@ +use crate::schema::Schema; + +const SCHEMA_JSON: &str = include_str!("extend_object_schema.json"); +const SCHEMA_GRAPHQL: &str = include_str!("extend_object_schema.graphql"); + +#[test] +fn ast_from_graphql_and_json_produce_the_same_schema() { + let json: graphql_introspection_query::introspection_response::IntrospectionResponse = + serde_json::from_str(SCHEMA_JSON).unwrap(); + let graphql_parser_schema = graphql_parser::parse_schema(SCHEMA_GRAPHQL) + .unwrap() + .into_static(); + let mut json = Schema::from(json); + let mut gql = Schema::from(graphql_parser_schema); + + assert!(vecs_match(&json.stored_scalars, &gql.stored_scalars)); + + // Root objects + { + assert_eq!( + json.get_object(json.query_type()).name, + gql.get_object(gql.query_type()).name + ); + assert_eq!( + json.mutation_type().map(|t| &json.get_object(t).name), + gql.mutation_type().map(|t| &gql.get_object(t).name), + "Mutation types don't match." + ); + assert_eq!( + json.subscription_type().map(|t| &json.get_object(t).name), + gql.subscription_type().map(|t| &gql.get_object(t).name), + "Subscription types don't match." + ); + } + + // Objects + { + let mut json_stored_objects: Vec<_> = json + .stored_objects + .drain(..) + .filter(|obj| !obj.name.starts_with("__")) + .collect(); + + assert_eq!( + json_stored_objects.len(), + gql.stored_objects.len(), + "Objects count matches." + ); + + json_stored_objects.sort_by(|a, b| a.name.cmp(&b.name)); + gql.stored_objects.sort_by(|a, b| a.name.cmp(&b.name)); + + for (j, g) in json_stored_objects + .iter_mut() + .filter(|obj| !obj.name.starts_with("__")) + .zip(gql.stored_objects.iter_mut()) + { + assert_eq!(j.name, g.name); + assert_eq!( + j.implements_interfaces.len(), + g.implements_interfaces.len(), + "{}", + j.name + ); + assert_eq!(j.fields.len(), g.fields.len(), "{}", j.name); + } + } + + // Unions + { + assert_eq!(json.stored_unions.len(), gql.stored_unions.len()); + + json.stored_unions.sort_by(|a, b| a.name.cmp(&b.name)); + gql.stored_unions.sort_by(|a, b| a.name.cmp(&b.name)); + + for (json, gql) in json.stored_unions.iter().zip(gql.stored_unions.iter()) { + assert_eq!(json.variants.len(), gql.variants.len()); + } + } + + // Interfaces + { + assert_eq!(json.stored_interfaces.len(), gql.stored_interfaces.len()); + + json.stored_interfaces.sort_by(|a, b| a.name.cmp(&b.name)); + gql.stored_interfaces.sort_by(|a, b| a.name.cmp(&b.name)); + + for (json, gql) in json + .stored_interfaces + .iter() + .zip(gql.stored_interfaces.iter()) + { + assert_eq!(json.fields.len(), gql.fields.len()); + } + } + + // Input objects + { + json.stored_enums = json + .stored_enums + .drain(..) + .filter(|enm| !enm.name.starts_with("__")) + .collect(); + assert_eq!(json.stored_inputs.len(), gql.stored_inputs.len()); + + json.stored_inputs.sort_by(|a, b| a.name.cmp(&b.name)); + gql.stored_inputs.sort_by(|a, b| a.name.cmp(&b.name)); + + for (json, gql) in json.stored_inputs.iter().zip(gql.stored_inputs.iter()) { + assert_eq!(json.fields.len(), gql.fields.len()); + } + } + + // Enums + { + assert_eq!(json.stored_enums.len(), gql.stored_enums.len()); + + json.stored_enums.sort_by(|a, b| a.name.cmp(&b.name)); + gql.stored_enums.sort_by(|a, b| a.name.cmp(&b.name)); + + for (json, gql) in json.stored_enums.iter().zip(gql.stored_enums.iter()) { + assert_eq!(json.variants.len(), gql.variants.len()); + } + } +} + +fn vecs_match(a: &[T], b: &[T]) -> bool { + a.len() == b.len() && a.iter().all(|a| b.iter().any(|b| a == b)) +} diff --git a/graphql_client_codegen/src/schema/tests/extend_object_schema.graphql b/graphql_client_codegen/src/schema/tests/extend_object_schema.graphql new file mode 100644 index 000000000..5a2be6d5a --- /dev/null +++ b/graphql_client_codegen/src/schema/tests/extend_object_schema.graphql @@ -0,0 +1,11 @@ +schema { + query: Query +} + +type Query { + foo: String +} + +extend type Query { + bar: Int +} diff --git a/graphql_client_codegen/src/schema/tests/extend_object_schema.json b/graphql_client_codegen/src/schema/tests/extend_object_schema.json new file mode 100644 index 000000000..a44bafddc --- /dev/null +++ b/graphql_client_codegen/src/schema/tests/extend_object_schema.json @@ -0,0 +1,1069 @@ +{ + "__schema": { + "queryType": { + "name": "Query" + }, + "mutationType": null, + "subscriptionType": null, + "types": [ + { + "kind": "OBJECT", + "name": "Query", + "description": null, + "fields": [ + { + "name": "foo", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "bar", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "String", + "description": "The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "Int", + "description": "The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "SCALAR", + "name": "Boolean", + "description": "The `Boolean` scalar type represents `true` or `false`.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Schema", + "description": "A GraphQL Schema defines the capabilities of a GraphQL server. It exposes all available types and directives on the server, as well as the entry points for query, mutation, and subscription operations.", + "fields": [ + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "types", + "description": "A list of all types supported by this server.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "queryType", + "description": "The type that query operations will be rooted at.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "mutationType", + "description": "If this server supports mutation, the type that mutation operations will be rooted at.", + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "subscriptionType", + "description": "If this server support subscription, the type that subscription operations will be rooted at.", + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "directives", + "description": "A list of all directives supported by this server.", + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Directive", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Type", + "description": "The fundamental unit of any GraphQL Schema is the type. There are many kinds of types in GraphQL as represented by the `__TypeKind` enum.\n\nDepending on the kind of a type, certain fields describe information about that type. Scalar types provide no information beyond a name, description and optional `specifiedByUrl`, while Enum types provide their values. Object and Interface types provide the fields they describe. Abstract types, Union and Interface, provide the Object types possible at runtime. List and NonNull types compose other types.", + "fields": [ + { + "name": "kind", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "__TypeKind", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "specifiedByUrl", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "fields", + "description": null, + "args": [ + { + "name": "includeDeprecated", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": "false", + "isDeprecated": false, + "deprecationReason": null + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Field", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "interfaces", + "description": null, + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "possibleTypes", + "description": null, + "args": [], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "enumValues", + "description": null, + "args": [ + { + "name": "includeDeprecated", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": "false", + "isDeprecated": false, + "deprecationReason": null + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__EnumValue", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "inputFields", + "description": null, + "args": [ + { + "name": "includeDeprecated", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": "false", + "isDeprecated": false, + "deprecationReason": null + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ofType", + "description": null, + "args": [], + "type": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "ENUM", + "name": "__TypeKind", + "description": "An enum describing what kind of type a given `__Type` is.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": [ + { + "name": "SCALAR", + "description": "Indicates this type is a scalar.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "OBJECT", + "description": "Indicates this type is an object. `fields` and `interfaces` are valid fields.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INTERFACE", + "description": "Indicates this type is an interface. `fields`, `interfaces`, and `possibleTypes` are valid fields.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "UNION", + "description": "Indicates this type is a union. `possibleTypes` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM", + "description": "Indicates this type is an enum. `enumValues` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_OBJECT", + "description": "Indicates this type is an input object. `inputFields` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "LIST", + "description": "Indicates this type is a list. `ofType` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "NON_NULL", + "description": "Indicates this type is a non-null. `ofType` is a valid field.", + "isDeprecated": false, + "deprecationReason": null + } + ], + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Field", + "description": "Object and Interface types are described by a list of Fields, each of which has a name, potentially a list of arguments, and a return type.", + "fields": [ + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "args", + "description": null, + "args": [ + { + "name": "includeDeprecated", + "description": null, + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + }, + "defaultValue": "false", + "isDeprecated": false, + "deprecationReason": null + } + ], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "type", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "isDeprecated", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "deprecationReason", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__InputValue", + "description": "Arguments provided to Fields or Directives and the input fields of an InputObject are represented as Input Values which describe their type and optionally a default value.", + "fields": [ + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "type", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__Type", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "defaultValue", + "description": "A GraphQL-formatted string representing the default value for this input value.", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "isDeprecated", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "deprecationReason", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__EnumValue", + "description": "One possible value for a given Enum. Enum values are unique values, not a placeholder for a string or numeric value. However an Enum value is returned in a JSON response as a string.", + "fields": [ + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "isDeprecated", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "deprecationReason", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "OBJECT", + "name": "__Directive", + "description": "A Directive provides a way to describe alternate runtime execution and type validation behavior in a GraphQL document.\n\nIn some cases, you need to provide options to alter GraphQL's execution behavior in ways field arguments will not suffice, such as conditionally including or skipping a field. Directives provide this by describing additional information to the executor.", + "fields": [ + { + "name": "name", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "description", + "description": null, + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "isRepeatable", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "locations", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "ENUM", + "name": "__DirectiveLocation", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "args", + "description": null, + "args": [], + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "__InputValue", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null + } + ], + "inputFields": null, + "interfaces": [], + "enumValues": null, + "possibleTypes": null + }, + { + "kind": "ENUM", + "name": "__DirectiveLocation", + "description": "A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.", + "fields": null, + "inputFields": null, + "interfaces": null, + "enumValues": [ + { + "name": "QUERY", + "description": "Location adjacent to a query operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "MUTATION", + "description": "Location adjacent to a mutation operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SUBSCRIPTION", + "description": "Location adjacent to a subscription operation.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FIELD", + "description": "Location adjacent to a field.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FRAGMENT_DEFINITION", + "description": "Location adjacent to a fragment definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FRAGMENT_SPREAD", + "description": "Location adjacent to a fragment spread.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INLINE_FRAGMENT", + "description": "Location adjacent to an inline fragment.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "VARIABLE_DEFINITION", + "description": "Location adjacent to a variable definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SCHEMA", + "description": "Location adjacent to a schema definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "SCALAR", + "description": "Location adjacent to a scalar definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "OBJECT", + "description": "Location adjacent to an object type definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "FIELD_DEFINITION", + "description": "Location adjacent to a field definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ARGUMENT_DEFINITION", + "description": "Location adjacent to an argument definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INTERFACE", + "description": "Location adjacent to an interface definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "UNION", + "description": "Location adjacent to a union definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM", + "description": "Location adjacent to an enum definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "ENUM_VALUE", + "description": "Location adjacent to an enum value definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_OBJECT", + "description": "Location adjacent to an input object type definition.", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "INPUT_FIELD_DEFINITION", + "description": "Location adjacent to an input object field definition.", + "isDeprecated": false, + "deprecationReason": null + } + ], + "possibleTypes": null + } + ], + "directives": [ + { + "name": "include", + "description": "Directs the executor to include this field or fragment only when the `if` argument is true.", + "isRepeatable": false, + "locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"], + "args": [ + { + "name": "if", + "description": "Included when true.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + } + ] + }, + { + "name": "skip", + "description": "Directs the executor to skip this field or fragment when the `if` argument is true.", + "isRepeatable": false, + "locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"], + "args": [ + { + "name": "if", + "description": "Skipped when true.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + } + ] + }, + { + "name": "deprecated", + "description": "Marks an element of a GraphQL schema as no longer supported.", + "isRepeatable": false, + "locations": [ + "FIELD_DEFINITION", + "ARGUMENT_DEFINITION", + "INPUT_FIELD_DEFINITION", + "ENUM_VALUE" + ], + "args": [ + { + "name": "reason", + "description": "Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "defaultValue": "\"No longer supported\"", + "isDeprecated": false, + "deprecationReason": null + } + ] + }, + { + "name": "specifiedBy", + "description": "Exposes a URL that specifies the behaviour of this scalar.", + "isRepeatable": false, + "locations": ["SCALAR"], + "args": [ + { + "name": "url", + "description": "The URL that specifies the behaviour of this scalar.", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + } + ] + } + ] + } +}