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
| Name | Type | Description |
|---|---|---|
| introspection | IntrospectionQuery | The introspection result data to build from. |
| options? | { assumeValid?: boolean } | Optional configuration for this operation. |
Returns
| Type | Description |
|---|---|
GraphQLSchema | The 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
| Name | Type | Description |
|---|---|---|
| options? | IntrospectionOptions | Optional configuration for this operation. |
Returns
| Type | Description |
|---|---|
string | The 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
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
| options? | IntrospectionOptions | Optional configuration for this operation. |
Returns
| Type | Description |
|---|---|
IntrospectionQuery | The introspection result data for the schema. |
Example
import { introspectionFromSchema } from 'graphql/utilities';
const result = introspectionFromSchema(schema);
// result contains the introspectionFromSchema return valueTypes
IntrospectionOptions
Interface. Options controlling which fields are included in the introspection query.
Members
| Name | Type | Description |
|---|---|---|
| descriptions? | boolean | Whether to include descriptions in the introspection result. Default: true |
| specifiedByUrl? | boolean | Whether to include specifiedByURL in the introspection result.Default: false |
| directiveIsRepeatable? | boolean | Whether to include isRepeatable flag on directives.Default: false |
| schemaDescription? | boolean | Whether to include description field on schema.Default: false |
| inputValueDeprecation? | boolean | Whether target GraphQL server support deprecation of input values. Default: false |
| experimentalDirectiveDeprecation? | boolean | Whether target GraphQL server supports deprecation of directives. Default: false |
| oneOf? | boolean | Whether target GraphQL server supports @oneOf input objects.Default: false |
| typeDepth? | number | How 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
| Name | Type | Description |
|---|---|---|
| __schema | IntrospectionSchema | The schema. |
IntrospectionSchema
Interface. The introspection representation of a GraphQL schema.
Members
| Name | Type | Description |
|---|---|---|
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| queryType | IntrospectionNamedTypeRef<IntrospectionObjectType> | The root object type used for query operations. |
| mutationType | null | undefined | IntrospectionNamedTypeRef<IntrospectionObjectType> | The root object type used for mutation operations, if supported. |
| subscriptionType | null | undefined | IntrospectionNamedTypeRef<IntrospectionObjectType> | The root object type used for subscription operations, if supported. |
| types | readonly IntrospectionType[] | Object types that belong to this union type. |
| directives | readonly 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
| Name | Type | Description |
|---|---|---|
| kind | ”SCALAR” | The introspection kind discriminator for this type reference or type. |
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| specifiedByURL? | null | undefined | string | URL identifying the behavior specified for this custom scalar. |
IntrospectionObjectType
Interface. The introspection representation of an object type.
Members
| Name | Type | Description |
|---|---|---|
| kind | ”OBJECT” | The introspection kind discriminator for this type reference or type. |
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| fields | readonly IntrospectionField[] | Fields declared by this object, interface, input object, or literal. |
| interfaces | readonly IntrospectionNamedTypeRef<IntrospectionInterfaceType>[] | Interfaces implemented by this object or interface type. |
IntrospectionInterfaceType
Interface. The introspection representation of an interface type.
Members
| Name | Type | Description |
|---|---|---|
| kind | ”INTERFACE” | The introspection kind discriminator for this type reference or type. |
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| fields | readonly IntrospectionField[] | Fields declared by this object, interface, input object, or literal. |
| interfaces | readonly IntrospectionNamedTypeRef<IntrospectionInterfaceType>[] | Interfaces implemented by this object or interface type. |
| possibleTypes | readonly IntrospectionNamedTypeRef<IntrospectionObjectType>[] | Object types that may be returned for this abstract type. |
IntrospectionUnionType
Interface. The introspection representation of a union type.
Members
| Name | Type | Description |
|---|---|---|
| kind | ”UNION” | The introspection kind discriminator for this type reference or type. |
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| possibleTypes | readonly IntrospectionNamedTypeRef<IntrospectionObjectType>[] | Object types that may be returned for this abstract type. |
IntrospectionEnumType
Interface. The introspection representation of an enum type.
Members
| Name | Type | Description |
|---|---|---|
| kind | ”ENUM” | The introspection kind discriminator for this type reference or type. |
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| enumValues | readonly IntrospectionEnumValue[] | Values declared by this enum type. |
IntrospectionInputObjectType
Interface. The introspection representation of an input object type.
Members
| Name | Type | Description |
|---|---|---|
| kind | ”INPUT_OBJECT” | The introspection kind discriminator for this type reference or type. |
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| inputFields | readonly IntrospectionInputValue[] | Input fields declared by this input object type. |
| isOneOf | boolean | Whether this input object uses the experimental OneOf input object semantics. |
IntrospectionListTypeRef
Interface. The introspection representation of a list type reference.
Type Parameters
| Name | Constraint | Default | Description |
|---|---|---|---|
| T | IntrospectionTypeRef | IntrospectionTypeRef | The introspection type reference wrapped by this list type reference. |
Members
| Name | Type | Description |
|---|---|---|
| kind | ”LIST” | The introspection kind discriminator for this type reference or type. |
| ofType | T | The type wrapped by this list or non-null type. |
IntrospectionNonNullTypeRef
Interface. The introspection representation of a non-null type reference.
Type Parameters
| Name | Constraint | Default | Description |
|---|---|---|---|
| T | IntrospectionTypeRef | IntrospectionTypeRef | The introspection type reference wrapped by this non-null type reference. |
Members
| Name | Type | Description |
|---|---|---|
| kind | ”NON_NULL” | The introspection kind discriminator for this type reference or type. |
| ofType | T | The 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
| Name | Constraint | Default | Description |
|---|---|---|---|
| T | IntrospectionType | IntrospectionType | The introspection type represented by this named type reference. |
Members
| Name | Type | Description |
|---|---|---|
| kind | T[“kind”] | The introspection kind discriminator for this type reference or type. |
| name | string | The GraphQL name for this schema element. |
IntrospectionField
Interface. The introspection representation of a field.
Members
| Name | Type | Description |
|---|---|---|
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| args | readonly IntrospectionInputValue[] | Arguments accepted by this field or directive. |
| type | IntrospectionOutputTypeRef | The GraphQL type reference or runtime type for this element. |
| isDeprecated | boolean | Whether this field, argument, enum value, or input value is deprecated. |
| deprecationReason | null | undefined | string | Reason this element is deprecated, if one was provided. |
IntrospectionInputValue
Interface. The introspection representation of an argument or input field.
Members
| Name | Type | Description |
|---|---|---|
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| type | IntrospectionInputTypeRef | The GraphQL type reference or runtime type for this element. |
| defaultValue | null | undefined | string | The default value used when no explicit value is supplied. |
| isDeprecated? | boolean | Whether this field, argument, enum value, or input value is deprecated. |
| deprecationReason? | null | undefined | string | Reason this element is deprecated, if one was provided. |
IntrospectionEnumValue
Interface. The introspection representation of an enum value.
Members
| Name | Type | Description |
|---|---|---|
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| isDeprecated | boolean | Whether this field, argument, enum value, or input value is deprecated. |
| deprecationReason | null | undefined | string | Reason this element is deprecated, if one was provided. |
IntrospectionDirective
Interface. The introspection representation of a directive.
Members
| Name | Type | Description |
|---|---|---|
| name | string | The GraphQL name for this schema element. |
| description? | null | undefined | string | Human-readable description for this schema element, if provided. |
| isRepeatable? | boolean | Whether this directive may appear more than once at the same location. |
| isDeprecated? | boolean | Whether this field, argument, enum value, or input value is deprecated. |
| deprecationReason? | null | undefined | string | Reason this element is deprecated, if one was provided. |
| locations | readonly DirectiveLocation[] | Locations where this directive may be applied. |
| args | readonly IntrospectionInputValue[] | Arguments accepted by this field or directive. |