graphql/utilities/introspection

Functions

buildClientSchema()

Build a GraphQLSchema for use by client tools.

Given the result of a client running the introspection query, creates and returns a GraphQLSchema instance which can be then used with all graphql-js tools, but cannot be used to execute a query, as introspection does not represent the “resolver”, “parse” or “serialize” functions or any other server-internal mechanisms.

This function expects a complete introspection result. Don’t forget to check the “errors” field of a server response before calling this function.

Signature:

buildClientSchema(introspection: IntrospectionQuery, options?: { assumeValid?: boolean }): GraphQLSchema

Arguments

NameTypeDescription
introspectionIntrospectionQueryThe introspection result data to build from.
options?{ assumeValid?: boolean }Optional configuration for this operation.

Returns

TypeDescription
GraphQLSchemaThe client schema represented by the introspection result.

Example

import { buildClientSchema, introspectionFromSchema, buildSchema } from 'graphql/utilities';
 
const schema = buildSchema('type Query { hello: String }');
const clientSchema = buildClientSchema(introspectionFromSchema(schema));
 
// clientSchema.getQueryType()?.name: 'Query'

getIntrospectionQuery()

Produce the GraphQL query recommended for a full schema introspection. Accepts optional IntrospectionOptions.

Signature:

getIntrospectionQuery(options?: IntrospectionOptions): string

Arguments

NameTypeDescription
options?IntrospectionOptionsOptional configuration for this operation.

Returns

TypeDescription
stringThe resolved introspection query.

Example

import { getIntrospectionQuery } from 'graphql/utilities';
 
const query = getIntrospectionQuery();
 
// query includes: '__schema'

introspectionFromSchema()

Build an IntrospectionQuery from a GraphQLSchema

IntrospectionQuery is useful for utilities that care about type and field relationships, but do not need to traverse through those relationships.

This is the inverse of buildClientSchema. The primary use case is outside of the server context, for instance when doing schema comparisons.

Signature:

introspectionFromSchema(schema: GraphQLSchema, options?: IntrospectionOptions): IntrospectionQuery

Arguments

NameTypeDescription
schemaGraphQLSchemaThe GraphQL schema to use.
options?IntrospectionOptionsOptional configuration for this operation.

Returns

TypeDescription
IntrospectionQueryThe introspection result data for the schema.

Example

import { introspectionFromSchema } from 'graphql/utilities';
 
const result = introspectionFromSchema(schema);
 
// result contains the introspectionFromSchema return value

Types

IntrospectionOptions

Interface. Options controlling which fields are included in the introspection query.

Members

NameTypeDescription
descriptions?booleanWhether to include descriptions in the introspection result.
Default: true
specifiedByUrl?booleanWhether to include specifiedByURL in the introspection result.
Default: false
directiveIsRepeatable?booleanWhether to include isRepeatable flag on directives.
Default: false
schemaDescription?booleanWhether to include description field on schema.
Default: false
inputValueDeprecation?booleanWhether target GraphQL server support deprecation of input values.
Default: false
experimentalDirectiveDeprecation?booleanWhether target GraphQL server supports deprecation of directives.
Default: false
oneOf?booleanWhether target GraphQL server supports @oneOf input objects.
Default: false
typeDepth?numberHow deep to recurse into nested types, larger values will result in more
accurate results, but have a higher load on the server.
Some servers might restrict the maximum query depth or complexity.
If that’s the case, try decreasing this value.
Default: 9

IntrospectionQuery

Interface. The result shape returned by a full introspection query.

Members

NameTypeDescription
__schemaIntrospectionSchemaThe schema.

IntrospectionSchema

Interface. The introspection representation of a GraphQL schema.

Members

NameTypeDescription
description?null | undefined | stringHuman-readable description for this schema element, if provided.
queryTypeIntrospectionNamedTypeRef<IntrospectionObjectType>The root object type used for query operations.
mutationTypenull | undefined | IntrospectionNamedTypeRef<IntrospectionObjectType>The root object type used for mutation operations, if supported.
subscriptionTypenull | undefined | IntrospectionNamedTypeRef<IntrospectionObjectType>The root object type used for subscription operations, if supported.
typesreadonly IntrospectionType[]Object types that belong to this union type.
directivesreadonly IntrospectionDirective[]Directives available in this schema or applied to this AST node.

IntrospectionType

Type alias. Any introspection representation of a GraphQL type.

type IntrospectionType = IntrospectionScalarType | IntrospectionObjectType | IntrospectionInterfaceType | IntrospectionUnionType | IntrospectionEnumType | IntrospectionInputObjectType;

IntrospectionOutputType

Type alias. An introspection type that can appear in output position.

type IntrospectionOutputType = IntrospectionScalarType | IntrospectionObjectType | IntrospectionInterfaceType | IntrospectionUnionType | IntrospectionEnumType;

IntrospectionInputType

Type alias. An introspection type that can appear in input position.

type IntrospectionInputType = IntrospectionScalarType | IntrospectionEnumType | IntrospectionInputObjectType;

IntrospectionScalarType

Interface. The introspection representation of a scalar type.

Members

NameTypeDescription
kind”SCALAR”The introspection kind discriminator for this type reference or type.
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
specifiedByURL?null | undefined | stringURL identifying the behavior specified for this custom scalar.

IntrospectionObjectType

Interface. The introspection representation of an object type.

Members

NameTypeDescription
kind”OBJECT”The introspection kind discriminator for this type reference or type.
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
fieldsreadonly IntrospectionField[]Fields declared by this object, interface, input object, or literal.
interfacesreadonly IntrospectionNamedTypeRef<IntrospectionInterfaceType>[]Interfaces implemented by this object or interface type.

IntrospectionInterfaceType

Interface. The introspection representation of an interface type.

Members

NameTypeDescription
kind”INTERFACE”The introspection kind discriminator for this type reference or type.
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
fieldsreadonly IntrospectionField[]Fields declared by this object, interface, input object, or literal.
interfacesreadonly IntrospectionNamedTypeRef<IntrospectionInterfaceType>[]Interfaces implemented by this object or interface type.
possibleTypesreadonly IntrospectionNamedTypeRef<IntrospectionObjectType>[]Object types that may be returned for this abstract type.

IntrospectionUnionType

Interface. The introspection representation of a union type.

Members

NameTypeDescription
kind”UNION”The introspection kind discriminator for this type reference or type.
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
possibleTypesreadonly IntrospectionNamedTypeRef<IntrospectionObjectType>[]Object types that may be returned for this abstract type.

IntrospectionEnumType

Interface. The introspection representation of an enum type.

Members

NameTypeDescription
kind”ENUM”The introspection kind discriminator for this type reference or type.
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
enumValuesreadonly IntrospectionEnumValue[]Values declared by this enum type.

IntrospectionInputObjectType

Interface. The introspection representation of an input object type.

Members

NameTypeDescription
kind”INPUT_OBJECT”The introspection kind discriminator for this type reference or type.
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
inputFieldsreadonly IntrospectionInputValue[]Input fields declared by this input object type.
isOneOfbooleanWhether this input object uses the experimental OneOf input object semantics.

IntrospectionListTypeRef

Interface. The introspection representation of a list type reference.

Type Parameters

NameConstraintDefaultDescription
TIntrospectionTypeRefIntrospectionTypeRefThe introspection type reference wrapped by this list type reference.

Members

NameTypeDescription
kind”LIST”The introspection kind discriminator for this type reference or type.
ofTypeTThe type wrapped by this list or non-null type.

IntrospectionNonNullTypeRef

Interface. The introspection representation of a non-null type reference.

Type Parameters

NameConstraintDefaultDescription
TIntrospectionTypeRefIntrospectionTypeRefThe introspection type reference wrapped by this non-null type reference.

Members

NameTypeDescription
kind”NON_NULL”The introspection kind discriminator for this type reference or type.
ofTypeTThe type wrapped by this list or non-null type.

IntrospectionTypeRef

Type alias. Any introspection representation of a type reference.

type IntrospectionTypeRef = IntrospectionNamedTypeRef | IntrospectionListTypeRef | IntrospectionNonNullTypeRef<IntrospectionNamedTypeRef | IntrospectionListTypeRef>;

IntrospectionOutputTypeRef

Type alias. An introspection type reference that can appear in output position.

type IntrospectionOutputTypeRef = IntrospectionNamedTypeRef<IntrospectionOutputType> | IntrospectionListTypeRef<IntrospectionOutputTypeRef> | IntrospectionNonNullTypeRef<IntrospectionNamedTypeRef<IntrospectionOutputType> | IntrospectionListTypeRef<IntrospectionOutputTypeRef>>;

IntrospectionInputTypeRef

Type alias. An introspection type reference that can appear in input position.

type IntrospectionInputTypeRef = IntrospectionNamedTypeRef<IntrospectionInputType> | IntrospectionListTypeRef<IntrospectionInputTypeRef> | IntrospectionNonNullTypeRef<IntrospectionNamedTypeRef<IntrospectionInputType> | IntrospectionListTypeRef<IntrospectionInputTypeRef>>;

IntrospectionNamedTypeRef

Interface. The introspection representation of a named type reference.

Type Parameters

NameConstraintDefaultDescription
TIntrospectionTypeIntrospectionTypeThe introspection type represented by this named type reference.

Members

NameTypeDescription
kindT[“kind”]The introspection kind discriminator for this type reference or type.
namestringThe GraphQL name for this schema element.

IntrospectionField

Interface. The introspection representation of a field.

Members

NameTypeDescription
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
argsreadonly IntrospectionInputValue[]Arguments accepted by this field or directive.
typeIntrospectionOutputTypeRefThe GraphQL type reference or runtime type for this element.
isDeprecatedbooleanWhether this field, argument, enum value, or input value is deprecated.
deprecationReasonnull | undefined | stringReason this element is deprecated, if one was provided.

IntrospectionInputValue

Interface. The introspection representation of an argument or input field.

Members

NameTypeDescription
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
typeIntrospectionInputTypeRefThe GraphQL type reference or runtime type for this element.
defaultValuenull | undefined | stringThe default value used when no explicit value is supplied.
isDeprecated?booleanWhether this field, argument, enum value, or input value is deprecated.
deprecationReason?null | undefined | stringReason this element is deprecated, if one was provided.

IntrospectionEnumValue

Interface. The introspection representation of an enum value.

Members

NameTypeDescription
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
isDeprecatedbooleanWhether this field, argument, enum value, or input value is deprecated.
deprecationReasonnull | undefined | stringReason this element is deprecated, if one was provided.

IntrospectionDirective

Interface. The introspection representation of a directive.

Members

NameTypeDescription
namestringThe GraphQL name for this schema element.
description?null | undefined | stringHuman-readable description for this schema element, if provided.
isRepeatable?booleanWhether this directive may appear more than once at the same location.
isDeprecated?booleanWhether this field, argument, enum value, or input value is deprecated.
deprecationReason?null | undefined | stringReason this element is deprecated, if one was provided.
locationsreadonly DirectiveLocation[]Locations where this directive may be applied.
argsreadonly IntrospectionInputValue[]Arguments accepted by this field or directive.