🎉 Explore GraphQLConf 2026 • May 19-21 • Fremont, CA • View the schedule
v17 APIgraphql/type

Create and inspect GraphQL type definitions and schemas.

These exports are also available from the root graphql package.

For documentation purposes, these exports are grouped into the following categories:

Category: Paths

Types

ResponsePath

Interface. Represents a linked response path from a field back to the root response.


Members
NameTypeDescription
prevPath | undefinedThe previous segment in the linked response path, or undefined at the root.
keystring | numberThe field name or list index for this response path segment.
typenamestring | undefinedThe runtime object type name associated with this path segment, if known.

Category: Names

Functions

assertName()

Upholds the spec rules about naming.

Signature:

assertName(name: string): string;

Arguments
NameTypeDescription
namestringThe GraphQL name to validate.

Returns
TypeDescription
stringThe validated GraphQL name.

Example
import { assertName } from 'graphql/type';
 
assertName('User'); // => 'User'
assertName('123User'); // throws an error

assertEnumValueName()

Upholds the spec rules about naming enum values.

Signature:

assertEnumValueName(name: string): string;

Arguments
NameTypeDescription
namestringThe GraphQL name to validate.

Returns
TypeDescription
stringThe validated GraphQL name.

Example
import { assertEnumValueName } from 'graphql/type';
 
assertEnumValueName('ACTIVE'); // => 'ACTIVE'
assertEnumValueName('true'); // throws an error

Category: Types

Classes:
GraphQLListGraphQLNonNullGraphQLScalarTypeGraphQLObjectTypeGraphQLInterfaceTypeGraphQLUnionTypeGraphQLEnumTypeGraphQLInputObjectType

Functions:
isType()assertType()isScalarType()assertScalarType()isObjectType()assertObjectType()isField()assertField()isArgument()assertArgument()isInterfaceType()assertInterfaceType()isUnionType()assertUnionType()isEnumType()assertEnumType()isEnumValue()assertEnumValue()isInputObjectType()assertInputObjectType()isInputField()assertInputField()assertListType()assertNonNullType()isInputType()assertInputType()isOutputType()assertOutputType()isLeafType()assertLeafType()isCompositeType()assertCompositeType()isAbstractType()assertAbstractType()isWrappingType()assertWrappingType()isNullableType()assertNullableType()isNamedType()assertNamedType()resolveReadonlyArrayThunk()resolveObjMapThunk()isRequiredArgument()isRequiredInputField()

Types:
GraphQLTypeGraphQLNullableInputTypeGraphQLInputTypeGraphQLNullableOutputTypeGraphQLOutputTypeGraphQLLeafTypeGraphQLCompositeTypeGraphQLAbstractTypeGraphQLWrappingTypeGraphQLNullableTypeGraphQLNamedTypeGraphQLNamedInputTypeGraphQLNamedOutputTypeThunkReadonlyArrayThunkObjMapGraphQLScalarTypeExtensionsGraphQLScalarSerializerGraphQLScalarOutputValueCoercerGraphQLScalarValueParserGraphQLScalarInputValueCoercerGraphQLScalarLiteralParserGraphQLScalarInputLiteralCoercerGraphQLScalarTypeConfigGraphQLObjectTypeExtensionsGraphQLObjectTypeConfigGraphQLTypeResolverGraphQLIsTypeOfFnGraphQLFieldResolverGraphQLResolveInfoHelpersGraphQLResolveInfoGraphQLFieldExtensionsGraphQLFieldConfigGraphQLFieldConfigArgumentMapGraphQLArgumentExtensionsGraphQLArgumentConfigGraphQLFieldConfigMapGraphQLFieldGraphQLArgumentGraphQLFieldMapGraphQLDefaultInputGraphQLInterfaceTypeExtensionsGraphQLInterfaceTypeConfigGraphQLUnionTypeExtensionsGraphQLUnionTypeConfigGraphQLEnumTypeExtensionsGraphQLEnumTypeConfigGraphQLEnumValueConfigMapGraphQLEnumValueExtensionsGraphQLEnumValueConfigGraphQLEnumValueGraphQLInputObjectTypeExtensionsGraphQLInputObjectTypeConfigGraphQLInputFieldExtensionsGraphQLInputFieldConfigGraphQLInputFieldConfigMapGraphQLInputFieldGraphQLInputFieldMap

Classes

GraphQLList

List Type Wrapper

A list is a wrapping type which points to another type. Lists are often created within the context of defining the fields of an object type.


Type Parameters
NameConstraintDefaultDescription
TGraphQLTypeThe GraphQL type wrapped by this list type.

Example
const PersonType = new GraphQLObjectType({
  name: 'Person',
  fields: () => ({
    parents: { type: new GraphQLList(PersonType) },
    children: { type: new GraphQLList(PersonType) },
  })
})

Constructor

Creates a GraphQLList instance.

Signature:

new GraphQLList(ofType: T);

Arguments
NameTypeDescription
ofTypeTThe type to wrap.

Members
NameTypeDescription
ofTypeTThe type wrapped by this list or non-null type.

toString()

Returns this wrapping type as a GraphQL type-reference string.

Signature:

toString(): string;

Returns
TypeDescription
stringThe GraphQL type-reference string.

Example
import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
 
const stringList = new GraphQLList(GraphQLString);
const requiredStringList = new GraphQLList(new GraphQLNonNull(GraphQLString));
 
stringList.toString(); // => '[String]'
requiredStringList.toString(); // => '[String!]'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { GraphQLList, GraphQLString } from 'graphql/type';
 
const stringList = new GraphQLList(GraphQLString);
 
stringList.toJSON(); // => '[String]'
JSON.stringify({ type: stringList }); // => '{"type":"[String]"}'

GraphQLNonNull

Non-Null Type Wrapper

A non-null is a wrapping type which points to another type. Non-null types enforce that their values are never null and can ensure an error is raised if this ever occurs during a request. It is useful for fields which you can make a strong guarantee on non-nullability, for example usually the id field of a database row will never be null.


Type Parameters
NameConstraintDefaultDescription
TGraphQLNullableTypeThe nullable GraphQL type wrapped by this non-null type.

Example
const RowType = new GraphQLObjectType({
  name: 'Row',
  fields: () => ({
    id: { type: new GraphQLNonNull(GraphQLString) },
  })
})

Note: the enforcement of non-nullability occurs within the executor.


Constructor

Creates a GraphQLNonNull instance.

Signature:

new GraphQLNonNull(ofType: T);

Arguments
NameTypeDescription
ofTypeTThe type to wrap.

Members
NameTypeDescription
ofTypeTThe type wrapped by this list or non-null type.

toString()

Returns this wrapping type as a GraphQL type-reference string.

Signature:

toString(): string;

Returns
TypeDescription
stringThe GraphQL type-reference string.

Example
import { GraphQLList, GraphQLNonNull, GraphQLString } from 'graphql/type';
 
const requiredString = new GraphQLNonNull(GraphQLString);
const requiredStringList = new GraphQLNonNull(
  new GraphQLList(GraphQLString),
);
 
requiredString.toString(); // => 'String!'
requiredStringList.toString(); // => '[String]!'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { GraphQLNonNull, GraphQLString } from 'graphql/type';
 
const requiredString = new GraphQLNonNull(GraphQLString);
 
requiredString.toJSON(); // => 'String!'
JSON.stringify({ type: requiredString }); // => '{"type":"String!"}'

GraphQLScalarType

Scalar Type Definition

Scalar types define the leaf values of a GraphQL response and the input values accepted by arguments and input object fields. A scalar type has a name and coercion functions that validate and convert runtime values and GraphQL literals.

If a type’s coerceOutputValue function returns null or does not return a value (i.e. it returns undefined) then an error will be raised and a null value will be returned in the response. Prefer validating inputs before execution so clients receive input diagnostics before result coercion fails. Custom scalar behavior is defined via the following functions:

  • coerceOutputValue(value): Implements “Result Coercion”. Given an internal value, produces an external value valid for this type. Returns undefined or throws an error to indicate invalid values.

  • coerceInputValue(value): Implements “Input Coercion” for values. Given an external value (for example, variable values), produces an internal value valid for this type. Returns undefined or throws an error to indicate invalid values.

  • coerceInputLiteral(ast): Implements “Input Coercion” for constant literals. Given a GraphQL literal (AST) (for example, an argument value), produces an internal value valid for this type. Returns undefined or throws an error to indicate invalid values.

  • valueToLiteral(value): Converts an external value to a GraphQL literal (AST). Returns undefined or throws an error to indicate invalid values.

Deprecated, to be removed in v18:

  • serialize(value): Implements “Result Coercion”. Renamed to coerceOutputValue().

  • parseValue(value): Implements “Input Coercion” for values. Renamed to coerceInputValue().

  • parseLiteral(ast): Implements “Input Coercion” for literals including non-specified replacement of variables embedded within complex scalars. Replaced by the combination of the replaceVariables() utility and the coerceInputLiteral() method.


Type Parameters
NameConstraintDefaultDescription
TInternalunknownInternal runtime representation for this scalar.
TExternalTInternalExternal representation accepted from or returned to callers.

Example
import { GraphQLScalarType, Kind } from 'graphql';
 
const ensureOdd = (value) => {
  if (!Number.isFinite(value)) {
    throw new Error(
      `Scalar "Odd" cannot represent "${value}" since it is not a finite number.`,
    );
  }
 
  if (value % 2 === 0) {
    throw new Error(`Scalar "Odd" cannot represent "${value}" since it is even.`);
  }
 
  return value;
};
 
const OddType = new GraphQLScalarType({
  name: 'Odd',
  coerceOutputValue: (value) => {
    return ensureOdd(value);
  },
  coerceInputValue: (value) => {
    return ensureOdd(value);
  },
  valueToLiteral: (value) => {
    return { kind: Kind.INT, value: String(ensureOdd(value)) };
  }
});

Constructor

Creates a GraphQLScalarType instance.

Signature:

new GraphQLScalarType(
  config: Readonly<
    GraphQLScalarTypeConfig<TInternal, TExternal>
  >,
);

Arguments
NameTypeDescription
configReadonly< GraphQLScalarTypeConfig<TInternal, TExternal> >Configuration describing this object.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
specifiedByURLMaybe<string>URL identifying the behavior specified for this custom scalar.
serializeGraphQLScalarSerializer<TExternal>Deprecated legacy serializer used to convert internal values for response
output. Use coerceOutputValue() instead.
parseValueGraphQLScalarValueParser<TInternal>Deprecated legacy parser used to convert externally provided input values.
Use coerceInputValue() instead.
parseLiteralGraphQLScalarLiteralParser<TInternal>Deprecated legacy parser used to convert externally provided input
literals. Use replaceVariables() and coerceInputLiteral() instead.
coerceOutputValueGraphQLScalarOutputValueCoercer<TExternal>Coercer used to convert internal scalar values for response output.
coerceInputValueGraphQLScalarInputValueCoercer<TInternal>Coercer used to convert externally provided scalar input values.
coerceInputLiteralGraphQLScalarInputLiteralCoercer<TInternal> | undefinedCoercer used to convert GraphQL scalar input literals.
valueToLiteralGraphQLScalarValueToLiteral | undefinedConverter used to produce GraphQL literals from runtime input values.
extensionsReadonly<GraphQLScalarTypeExtensions>Extension fields to include in the formatted result.
astNodeMaybe<ScalarTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodesreadonly ScalarTypeExtensionNode[]AST extension nodes applied to this schema element.

toConfig()

Returns a normalized configuration object for this object.

Signature:

toConfig(): GraphQLScalarTypeNormalizedConfig<
  TInternal,
  TExternal
>;

Returns
TypeDescription
GraphQLScalarTypeNormalizedConfig<TInternal, TExternal>A configuration object that can be used to recreate this object.

Example
import { GraphQLScalarType } from 'graphql/type';
 
const Url = new GraphQLScalarType({
  name: 'Url',
  description: 'An absolute URL string.',
  specifiedByURL: 'https://url.spec.whatwg.org/',
});
 
const config = Url.toConfig();
const UrlCopy = new GraphQLScalarType(config);
 
config.name; // => 'Url'
config.specifiedByURL; // => 'https://url.spec.whatwg.org/'
UrlCopy.name; // => Url.name

toString()

Returns the schema coordinate identifying this scalar type.

Signature:

toString(): string;

Returns
TypeDescription
stringThe schema coordinate for this scalar type.

Example
import { GraphQLScalarType } from 'graphql/type';
 
const DateTime = new GraphQLScalarType({ name: 'DateTime' });
 
DateTime.toString(); // => 'DateTime'
String(DateTime); // => 'DateTime'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { GraphQLScalarType } from 'graphql/type';
 
const DateTime = new GraphQLScalarType({ name: 'DateTime' });
 
DateTime.toJSON(); // => 'DateTime'
JSON.stringify({ type: DateTime }); // => '{"type":"DateTime"}'

GraphQLObjectType

Object Type Definition

Almost all of the GraphQL types you define will be object types. Object types have a name, but most importantly describe their fields.


Type Parameters
NameConstraintDefaultDescription
TSourceanySource object type passed to resolvers.
TContextanyContext object type passed to resolvers.
TAbstractanyRuntime value type used for abstract type resolution.

Example 1
const AddressType = new GraphQLObjectType({
  name: 'Address',
  fields: {
    street: { type: GraphQLString },
    number: { type: GraphQLInt },
    formatted: {
      type: GraphQLString,
      resolve: (obj) => {
        return obj.number + ' ' + obj.street
      }
    }
  }
});

Example 2

When two types need to refer to each other, or a type needs to refer to itself in a field, you can use a function expression (aka a closure or a thunk) to supply the fields lazily.

const PersonType = new GraphQLObjectType({
  name: 'Person',
  fields: () => ({
    name: { type: GraphQLString },
    bestFriend: { type: PersonType },
  })
});

Constructor

Creates a GraphQLObjectType instance.

Signature:

new GraphQLObjectType(
  config: Readonly<
    GraphQLObjectTypeConfig<
      TSource,
      TContext,
      TAbstract
    >
  >,
);

Arguments
NameTypeDescription
configReadonly< GraphQLObjectTypeConfig< TSource, TContext, TAbstract > >Configuration describing this object.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
isTypeOfMaybe< GraphQLIsTypeOfFn<TAbstract, TContext> >Predicate used to determine whether a runtime value belongs to this object type.
extensionsReadonly< GraphQLObjectTypeExtensions<TSource, TContext> >Extension fields to include in the formatted result.
astNodeMaybe<ObjectTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodesreadonly ObjectTypeExtensionNode[]AST extension nodes applied to this schema element.

getFields()

Returns the fields defined by this type.

Signature:

getFields(): GraphQLFieldMap<
  TSource,
  TContext
>;

Returns
TypeDescription
GraphQLFieldMap<TSource, TContext>The fields keyed by field name.

Example
import { buildSchema } from 'graphql/utilities';
import { assertObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  type User {
    id: ID!
    name: String
  }
 
  type Query {
    viewer: User
  }
`);
 
const User = assertObjectType(schema.getType('User'));
const fields = User.getFields();
 
Object.keys(fields); // => ['id', 'name']
String(fields.id.type); // => 'ID!'

getInterfaces()

Returns the interfaces implemented by this type.

Signature:

getInterfaces(): readonly GraphQLInterfaceType[];

Returns
TypeDescription
readonly GraphQLInterfaceType[]The implemented interfaces.

Example
import { buildSchema } from 'graphql/utilities';
import { assertObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Query {
    viewer: User
  }
`);
 
const User = assertObjectType(schema.getType('User'));
 
User.getInterfaces().map((type) => type.name); // => ['Node']

toConfig()

Returns a normalized configuration object for this object.

Signature:

toConfig(): GraphQLObjectTypeNormalizedConfig<
  TSource,
  TContext,
  TAbstract
>;

Returns
TypeDescription
GraphQLObjectTypeNormalizedConfig< TSource, TContext, TAbstract >A configuration object that can be used to recreate this object.

Example
import { GraphQLObjectType, GraphQLString } from 'graphql/type';
 
const User = new GraphQLObjectType({
  name: 'User',
  fields: {
    name: { type: GraphQLString },
  },
});
 
const config = User.toConfig();
const UserCopy = new GraphQLObjectType(config);
 
config.fields.name.type; // => GraphQLString
UserCopy.getFields().name.type; // => GraphQLString

toString()

Returns the schema coordinate identifying this object type.

Signature:

toString(): string;

Returns
TypeDescription
stringThe schema coordinate for this object type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  type User {
    name: String
  }
 
  type Query {
    viewer: User
  }
`);
 
const User = assertObjectType(schema.getType('User'));
 
User.toString(); // => 'User'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { GraphQLObjectType, GraphQLString } from 'graphql/type';
 
const User = new GraphQLObjectType({
  name: 'User',
  fields: { name: { type: GraphQLString } },
});
 
User.toJSON(); // => 'User'
JSON.stringify({ type: User }); // => '{"type":"User"}'

GraphQLInterfaceType

Interface Type Definition

When a field can return one of a heterogeneous set of types, a Interface type is used to describe what types are possible, what fields are in common across all types, as well as a function to determine which type is actually used when the field is resolved.


Type Parameters
NameConstraintDefaultDescription
TSourceanySource object type passed to resolvers.
TContextanyContext object type passed to resolvers.

Example
const EntityType = new GraphQLInterfaceType({
  name: 'Entity',
  fields: {
    name: { type: GraphQLString }
  }
});

Constructor

Creates a GraphQLInterfaceType instance.

Signature:

new GraphQLInterfaceType(
  config: Readonly<
    GraphQLInterfaceTypeConfig<TSource, TContext>
  >,
);

Arguments
NameTypeDescription
configReadonly< GraphQLInterfaceTypeConfig<TSource, TContext> >Configuration describing this object.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
resolveTypeMaybe< GraphQLTypeResolver<TSource, TContext> >Function that resolves the concrete object type for this abstract type.
extensionsReadonly<GraphQLInterfaceTypeExtensions>Extension fields to include in the formatted result.
astNodeMaybe<InterfaceTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodesreadonly InterfaceTypeExtensionNode[]AST extension nodes applied to this schema element.

getFields()

Returns the fields defined by this type.

Signature:

getFields(): GraphQLFieldMap<
  TSource,
  TContext
>;

Returns
TypeDescription
GraphQLFieldMap<TSource, TContext>The fields keyed by field name.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInterfaceType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Query {
    node: Node
  }
`);
 
const Node = assertInterfaceType(schema.getType('Node'));
const fields = Node.getFields();
 
Object.keys(fields); // => ['id']
String(fields.id.type); // => 'ID!'

getInterfaces()

Returns the interfaces implemented by this type.

Signature:

getInterfaces(): readonly GraphQLInterfaceType[];

Returns
TypeDescription
readonly GraphQLInterfaceType[]The implemented interfaces.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInterfaceType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Resource {
    url: String!
  }
 
  interface Image implements Resource {
    url: String!
    width: Int
  }
 
  type Photo implements Resource & Image {
    url: String!
    width: Int
  }
 
  type Query {
    image: Image
  }
`);
 
const Image = assertInterfaceType(schema.getType('Image'));
 
Image.getInterfaces().map((type) => type.name); // => ['Resource']

toConfig()

Returns a normalized configuration object for this object.

Signature:

toConfig(): GraphQLInterfaceTypeNormalizedConfig<
  TSource,
  TContext
>;

Returns
TypeDescription
GraphQLInterfaceTypeNormalizedConfig<TSource, TContext>A configuration object that can be used to recreate this object.

Example
import { GraphQLID, GraphQLInterfaceType, GraphQLNonNull } from 'graphql/type';
 
const Node = new GraphQLInterfaceType({
  name: 'Node',
  fields: {
    id: { type: new GraphQLNonNull(GraphQLID) },
  },
});
 
const config = Node.toConfig();
const NodeCopy = new GraphQLInterfaceType(config);
 
String(config.fields.id.type); // => 'ID!'
String(NodeCopy.getFields().id.type); // => 'ID!'

toString()

Returns the schema coordinate identifying this interface type.

Signature:

toString(): string;

Returns
TypeDescription
stringThe schema coordinate for this interface type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInterfaceType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Query {
    node: Node
  }
`);
 
const Node = assertInterfaceType(schema.getType('Node'));
 
Node.toString(); // => 'Node'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { GraphQLInterfaceType, GraphQLString } from 'graphql/type';
 
const Named = new GraphQLInterfaceType({
  name: 'Named',
  fields: { name: { type: GraphQLString } },
});
 
Named.toJSON(); // => 'Named'
JSON.stringify({ type: Named }); // => '{"type":"Named"}'

GraphQLUnionType

Union Type Definition

When a field can return one of a heterogeneous set of types, a Union type is used to describe what types are possible as well as providing a function to determine which type is actually used when the field is resolved.


Type Parameters
NameConstraintDefaultDescription
TSourceanySource object type passed to resolvers.
TContextanyContext object type passed to resolvers.

Example
const PetType = new GraphQLUnionType({
  name: 'Pet',
  types: [DogType, CatType],
  resolveType: (value) => {
    if (value instanceof Dog) {
      return DogType;
    }
    if (value instanceof Cat) {
      return CatType;
    }
  }
});

Constructor

Creates a GraphQLUnionType instance.

Signature:

new GraphQLUnionType(
  config: Readonly<
    GraphQLUnionTypeConfig<TSource, TContext>
  >,
);

Arguments
NameTypeDescription
configReadonly< GraphQLUnionTypeConfig<TSource, TContext> >Configuration describing this object.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
resolveTypeMaybe< GraphQLTypeResolver<TSource, TContext> >Function that resolves the concrete object type for this abstract type.
extensionsReadonly<GraphQLUnionTypeExtensions>Extension fields to include in the formatted result.
astNodeMaybe<UnionTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodesreadonly UnionTypeExtensionNode[]AST extension nodes applied to this schema element.

getTypes()

Returns the object types included in this union.

Signature:

getTypes(): readonly GraphQLObjectType[];

Returns
TypeDescription
readonly GraphQLObjectType[]The union member object types.

Example
import { buildSchema } from 'graphql/utilities';
import { assertUnionType } from 'graphql/type';
 
const schema = buildSchema(`
  type Photo {
    url: String!
  }
 
  type Video {
    url: String!
  }
 
  union Media = Photo | Video
 
  type Query {
    media: [Media]
  }
`);
 
const Media = assertUnionType(schema.getType('Media'));
 
Media.getTypes().map((type) => type.name); // => ['Photo', 'Video']

toConfig()

Returns a normalized configuration object for this object.

Signature:

toConfig(): GraphQLUnionTypeNormalizedConfig<
  TSource,
  TContext
>;

Returns
TypeDescription
GraphQLUnionTypeNormalizedConfig<TSource, TContext>A configuration object that can be used to recreate this object.

Example
import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type';
 
const Photo = new GraphQLObjectType({
  name: 'Photo',
  fields: { url: { type: GraphQLString } },
});
const Video = new GraphQLObjectType({
  name: 'Video',
  fields: { url: { type: GraphQLString } },
});
const Media = new GraphQLUnionType({
  name: 'Media',
  types: [Photo, Video],
});
 
const config = Media.toConfig();
const MediaCopy = new GraphQLUnionType(config);
 
MediaCopy.getTypes().map((type) => type.name); // => ['Photo', 'Video']

toString()

Returns the schema coordinate identifying this union type.

Signature:

toString(): string;

Returns
TypeDescription
stringThe schema coordinate for this union type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertUnionType } from 'graphql/type';
 
const schema = buildSchema(`
  type Photo {
    url: String!
  }
 
  union SearchResult = Photo
 
  type Query {
    search: [SearchResult]
  }
`);
 
const SearchResult = assertUnionType(schema.getType('SearchResult'));
 
SearchResult.toString(); // => 'SearchResult'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { GraphQLObjectType, GraphQLString, GraphQLUnionType } from 'graphql/type';
 
const Photo = new GraphQLObjectType({
  name: 'Photo',
  fields: { url: { type: GraphQLString } },
});
const SearchResult = new GraphQLUnionType({
  name: 'SearchResult',
  types: [Photo],
});
 
SearchResult.toJSON(); // => 'SearchResult'
JSON.stringify({ type: SearchResult }); // => '{"type":"SearchResult"}'

GraphQLEnumType

Enum Type Definition

Enum types define leaf values whose serialized form is one of a fixed set of GraphQL enum names. Internally, enum values can map to any runtime value, often integers.


Example
import { GraphQLEnumType } from 'graphql/type';
 
const RGBType = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
RGBType.getValue('GREEN')?.value; // => 1

Note: If a value is not provided in a definition, the name of the enum value will be used as its internal value.


Constructor

Creates a GraphQLEnumType instance.

Signature:

new GraphQLEnumType(config: Readonly<GraphQLEnumTypeConfig>);

Arguments
NameTypeDescription
configReadonly<GraphQLEnumTypeConfig>Configuration describing this object.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
extensionsReadonly<GraphQLEnumTypeExtensions>Extension fields to include in the formatted result.
astNodeMaybe<EnumTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodesreadonly EnumTypeExtensionNode[]AST extension nodes applied to this schema element.

getValues()

Returns the values defined by this enum type.

Signature:

getValues(): readonly GraphQLEnumValue[];

Returns
TypeDescription
readonly GraphQLEnumValue[]Enum value definitions in schema order.

Example
import { buildSchema } from 'graphql/utilities';
import { assertEnumType } from 'graphql/type';
 
const schema = buildSchema(`
  enum Episode {
    NEW_HOPE
    EMPIRE
    JEDI
  }
 
  type Query {
    episode: Episode
  }
`);
 
const Episode = assertEnumType(schema.getType('Episode'));
 
Episode.getValues().map((value) => value.name); // => ['NEW_HOPE', 'EMPIRE', 'JEDI']

getValue()

Returns the enum value definition for a value name.

Signature:

getValue(
  name: string,
): Maybe<GraphQLEnumValue>;

Arguments
NameTypeDescription
namestringThe GraphQL name to look up.

Returns
TypeDescription
Maybe<GraphQLEnumValue>The matching enum value definition, if it exists.

Example
import { buildSchema } from 'graphql/utilities';
import { assertEnumType } from 'graphql/type';
 
const schema = buildSchema(`
  enum Episode {
    NEW_HOPE
    EMPIRE
  }
 
  type Query {
    episode: Episode
  }
`);
 
const Episode = assertEnumType(schema.getType('Episode'));
 
Episode.getValue('EMPIRE')?.name; // => 'EMPIRE'
Episode.getValue('JEDI'); // => undefined

serialize() Deprecated

Serializes a runtime enum value as a GraphQL enum name.

Signature:

serialize(
  outputValue: unknown,
): Maybe<string>;

Arguments
NameTypeDescription
outputValueunknownRuntime enum value to serialize.

Returns
TypeDescription
Maybe<string>The GraphQL enum name for the runtime value.
This deprecated method delegates to coerceOutputValue(); call
coerceOutputValue() directly instead.

Example
import { GraphQLEnumType } from 'graphql/type';
 
const RGB = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
RGB.serialize(1); // => 'GREEN'
RGB.serialize(3); // throws an error

coerceOutputValue()

Coerces a runtime enum value to a GraphQL enum name.

Signature:

coerceOutputValue(
  outputValue: unknown,
): Maybe<string>;

Arguments
NameTypeDescription
outputValueunknownRuntime enum value to coerce.

Returns
TypeDescription
Maybe<string>The GraphQL enum name for the runtime value.

Example
import { GraphQLEnumType } from 'graphql/type';
 
const RGB = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
RGB.coerceOutputValue(1); // => 'GREEN'
RGB.coerceOutputValue(3); // throws an error

parseValue() Deprecated

Deprecated legacy enum parser for externally provided input values. Use coerceInputValue() instead.

Signature:

parseValue(
  inputValue: unknown,
  hideSuggestions?: Maybe<boolean>,
): any;

Arguments
NameTypeDescription
inputValueunknownExternal enum name to parse.
hideSuggestions?Maybe<boolean>Whether suggestion text should be omitted from errors.

Returns
TypeDescription
anyThe internal runtime value for the enum name.

Example
import { GraphQLEnumType } from 'graphql/type';
 
const RGB = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
RGB.parseValue('BLUE'); // => 2
RGB.parseValue('PURPLE', true); // throws an error

coerceInputValue()

Coerces an external enum name to its internal runtime value.

Signature:

coerceInputValue(
  inputValue: unknown,
  hideSuggestions?: Maybe<boolean>,
): any;

Arguments
NameTypeDescription
inputValueunknownExternal enum name to coerce.
hideSuggestions?Maybe<boolean>Whether suggestion text should be omitted from errors.

Returns
TypeDescription
anyThe internal runtime value for the enum name.

Example
import { GraphQLEnumType } from 'graphql/type';
 
const RGB = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
RGB.coerceInputValue('BLUE'); // => 2
RGB.coerceInputValue('PURPLE'); // throws an error
RGB.coerceInputValue(2); // throws an error

parseLiteral() Deprecated

Deprecated legacy enum parser for externally provided input literals. Use coerceInputLiteral() instead.

Signature:

parseLiteral(
  valueNode: ValueNode,
  _variables: Maybe<ObjMap<unknown>>,
  hideSuggestions?: Maybe<boolean>,
): any;

Arguments
NameTypeDescription
valueNodeValueNodeEnum value AST node to parse.
_variablesMaybe<ObjMap<unknown>>Deprecated variable values parameter that is no longer used.
hideSuggestions?Maybe<boolean>Whether suggestion text should be omitted from errors.

Returns
TypeDescription
anyThe internal runtime value for the enum literal.

Example
import { parseValue } from 'graphql/language';
import { GraphQLEnumType } from 'graphql/type';
 
const RGB = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
RGB.parseLiteral(parseValue('RED')); // => 0
RGB.parseLiteral(parseValue('"RED"')); // throws an error

coerceInputLiteral()

Coerces an enum value AST node to its internal runtime value.

Signature:

coerceInputLiteral(
  valueNode: ConstValueNode,
  hideSuggestions?: Maybe<boolean>,
): any;

Arguments
NameTypeDescription
valueNodeConstValueNodeEnum value AST node to coerce.
hideSuggestions?Maybe<boolean>Whether suggestion text should be omitted from errors.

Returns
TypeDescription
anyThe internal runtime value for the enum literal.

Example
import { parseConstValue } from 'graphql/language';
import { GraphQLEnumType } from 'graphql/type';
 
const RGB = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
RGB.coerceInputLiteral(parseConstValue('RED')); // => 0
RGB.coerceInputLiteral(parseConstValue('"RED"'), true); // throws an error

valueToLiteral()

Converts a runtime enum value to a GraphQL enum value AST node.

Signature:

valueToLiteral(
  value: unknown,
): ConstValueNode | undefined;

Arguments
NameTypeDescription
valueunknownRuntime enum value to convert.

Returns
TypeDescription
ConstValueNode | undefinedEnum value AST node, or undefined if the value is invalid.

Example
import { print } from 'graphql/language';
import { GraphQLEnumType } from 'graphql/type';
 
const RGB = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
print(RGB.valueToLiteral(2)); // => 'BLUE'
RGB.valueToLiteral(3); // => undefined

toConfig()

Returns a normalized configuration object for this object.

Signature:

toConfig(): GraphQLEnumTypeNormalizedConfig;

Returns
TypeDescription
GraphQLEnumTypeNormalizedConfigA configuration object that can be used to recreate this object.

Example
import { GraphQLEnumType } from 'graphql/type';
 
const RGB = new GraphQLEnumType({
  name: 'RGB',
  values: {
    RED: { value: 0 },
    GREEN: { value: 1 },
    BLUE: { value: 2 },
  },
});
 
const config = RGB.toConfig();
const RGBCopy = new GraphQLEnumType(config);
 
config.values.GREEN.value; // => 1
RGBCopy.coerceOutputValue(2); // => 'BLUE'

toString()

Returns the schema coordinate identifying this enum type.

Signature:

toString(): string;

Returns
TypeDescription
stringThe schema coordinate for this enum type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertEnumType } from 'graphql/type';
 
const schema = buildSchema(`
  enum Episode {
    NEW_HOPE
  }
 
  type Query {
    episode: Episode
  }
`);
 
const Episode = assertEnumType(schema.getType('Episode'));
 
Episode.toString(); // => 'Episode'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { GraphQLEnumType } from 'graphql/type';
 
const Episode = new GraphQLEnumType({
  name: 'Episode',
  values: {
    NEW_HOPE: {},
  },
});
 
Episode.toJSON(); // => 'Episode'
JSON.stringify({ type: Episode }); // => '{"type":"Episode"}'

GraphQLInputObjectType

Input Object Type Definition

An input object defines a structured collection of fields which may be supplied to a field argument.

Using NonNull will ensure that a value must be provided by the query


Example
const GeoPoint = new GraphQLInputObjectType({
  name: 'GeoPoint',
  fields: {
    lat: { type: new GraphQLNonNull(GraphQLFloat) },
    lon: { type: new GraphQLNonNull(GraphQLFloat) },
    alt: { type: GraphQLFloat, default: { value: 0 } },
  }
});

Constructor

Creates a GraphQLInputObjectType instance.

Signature:

new GraphQLInputObjectType(config: Readonly<GraphQLInputObjectTypeConfig>);

Arguments
NameTypeDescription
configReadonly<GraphQLInputObjectTypeConfig>Configuration describing this object.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
extensionsReadonly<GraphQLInputObjectTypeExtensions>Extension fields to include in the formatted result.
astNodeMaybe<InputObjectTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodesreadonly InputObjectTypeExtensionNode[]AST extension nodes applied to this schema element.
isOneOfbooleanWhether this input object uses the experimental OneOf input object semantics.

getFields()

Returns the fields defined by this type.

Signature:

getFields(): GraphQLInputFieldMap;

Returns
TypeDescription
GraphQLInputFieldMapThe fields keyed by field name.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInputObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
    commentary: String = ""
  }
 
  type Query {
    reviews(filter: ReviewInput): [String]
  }
`);
 
const ReviewInput = assertInputObjectType(schema.getType('ReviewInput'));
const fields = ReviewInput.getFields();
 
Object.keys(fields); // => ['stars', 'commentary']
fields.commentary.default; // => { literal: { kind: 'StringValue', value: '' } }

toConfig()

Returns a normalized configuration object for this object.

Signature:

toConfig(): GraphQLInputObjectTypeNormalizedConfig;

Returns
TypeDescription
GraphQLInputObjectTypeNormalizedConfigA configuration object that can be used to recreate this object.

Example
import {
  GraphQLInputObjectType,
  GraphQLInt,
  GraphQLNonNull,
} from 'graphql/type';
 
const ReviewInput = new GraphQLInputObjectType({
  name: 'ReviewInput',
  fields: {
    stars: { type: new GraphQLNonNull(GraphQLInt) },
  },
});
 
const config = ReviewInput.toConfig();
const ReviewInputCopy = new GraphQLInputObjectType(config);
 
String(config.fields.stars.type); // => 'Int!'
String(ReviewInputCopy.getFields().stars.type); // => 'Int!'

toString()

Returns the schema coordinate identifying this input object type.

Signature:

toString(): string;

Returns
TypeDescription
stringThe schema coordinate for this input object type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInputObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type Query {
    reviews(filter: ReviewInput): [String]
  }
`);
 
const ReviewInput = assertInputObjectType(schema.getType('ReviewInput'));
 
ReviewInput.toString(); // => 'ReviewInput'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { GraphQLInputObjectType, GraphQLString } from 'graphql/type';
 
const ReviewInput = new GraphQLInputObjectType({
  name: 'ReviewInput',
  fields: {
    commentary: { type: GraphQLString },
  },
});
 
ReviewInput.toJSON(); // => 'ReviewInput'
JSON.stringify({ type: ReviewInput }); // => '{"type":"ReviewInput"}'

Functions

isType()

Returns true when the value is any GraphQL type.

Signature:

isType(
  type: unknown,
): type is GraphQLType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLTypeTrue when the value is any GraphQL type.

Example
import { buildSchema } from 'graphql/utilities';
import { GraphQLList, GraphQLString, isType } from 'graphql/type';
 
const schema = buildSchema(`
  type Query {
    name: String
  }
`);
 
isType(GraphQLString); // => true
isType(new GraphQLList(GraphQLString)); // => true
isType(schema.getType('Query')); // => true
isType('String'); // => false

assertType()

Returns the value as a GraphQL type, or throws if it is not one.

Signature:

assertType(type: unknown): GraphQLType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLTypeThe value typed as a GraphQL type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertType } from 'graphql/type';
 
const schema = buildSchema(`
  type Query {
    name: String
  }
`);
 
const queryType = assertType(schema.getType('Query'));
 
queryType.toString(); // => 'Query'
assertType('Query'); // throws an error

isScalarType()

There are predicates for each kind of GraphQL type.

Signature:

isScalarType(
  type: unknown,
): type is GraphQLScalarType<unknown, unknown>;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLScalarType<unknown, unknown>True when the value is a GraphQLScalarType.

Example
import { buildSchema } from 'graphql/utilities';
import { isScalarType } from 'graphql/type';
 
const schema = buildSchema(`
  scalar DateTime
 
  type Query {
    createdAt: DateTime
  }
`);
 
isScalarType(schema.getType('DateTime')); // => true
isScalarType(schema.getType('Query')); // => false

assertScalarType()

Returns the value as a GraphQLScalarType, or throws if it is not one.

Signature:

assertScalarType(type: unknown): GraphQLScalarType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLScalarTypeThe value typed as a GraphQLScalarType.

Example
import { buildSchema } from 'graphql/utilities';
import { assertScalarType } from 'graphql/type';
 
const schema = buildSchema(`
  scalar DateTime
 
  type Query {
    createdAt: DateTime
  }
`);
 
const dateTimeType = assertScalarType(schema.getType('DateTime'));
 
dateTimeType.name; // => 'DateTime'
assertScalarType(schema.getType('Query')); // throws an error

isObjectType()

Returns true when the value is a GraphQLObjectType.

Signature:

isObjectType(
  type: unknown,
): type is GraphQLObjectType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLObjectTypeTrue when the value is a GraphQLObjectType.

Example
import { buildSchema } from 'graphql/utilities';
import { isObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type User {
    name: String
  }
 
  type Query {
    user: User
  }
`);
 
isObjectType(schema.getType('User')); // => true
isObjectType(schema.getType('ReviewInput')); // => false

assertObjectType()

Returns the value as a GraphQLObjectType, or throws if it is not one.

Signature:

assertObjectType(type: unknown): GraphQLObjectType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLObjectTypeThe value typed as a GraphQLObjectType.

Example
import { buildSchema } from 'graphql/utilities';
import { assertObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type User {
    name: String
  }
 
  type Query {
    user: User
  }
`);
 
const userType = assertObjectType(schema.getType('User'));
 
Object.keys(userType.getFields()); // => ['name']
assertObjectType(schema.getType('ReviewInput')); // throws an error

isField()

Returns true when the value is a resolved GraphQL field definition.

Signature:

isField(
  field: unknown,
): field is GraphQLField;

Arguments
NameTypeDescription
fieldunknownValue to inspect.

Returns
TypeDescription
field is GraphQLFieldTrue when the value is a GraphQLField.

Example
import { buildSchema } from 'graphql/utilities';
import { isField } from 'graphql/type';
 
const schema = buildSchema('type Query { greeting: String }');
const field = schema.getQueryType().getFields().greeting;
 
isField(field); // => true
isField(schema.getQueryType()); // => false

assertField()

Returns the value as a GraphQLField, or throws if it is not one.

Signature:

assertField(field: unknown): GraphQLField;

Arguments
NameTypeDescription
fieldunknownValue to inspect.

Returns
TypeDescription
GraphQLFieldThe value typed as a GraphQLField.

Example
import { buildSchema } from 'graphql/utilities';
import { assertField } from 'graphql/type';
 
const schema = buildSchema('type Query { greeting: String }');
const field = assertField(schema.getQueryType().getFields().greeting);
 
field.name; // => 'greeting'
assertField(schema.getQueryType()); // throws an error

isArgument()

Returns true when the value is a resolved GraphQL argument definition.

Signature:

isArgument(
  arg: unknown,
): arg is GraphQLArgument;

Arguments
NameTypeDescription
argunknownValue to inspect.

Returns
TypeDescription
arg is GraphQLArgumentTrue when the value is a GraphQLArgument.

Example
import { buildSchema } from 'graphql/utilities';
import { isArgument } from 'graphql/type';
 
const schema = buildSchema('type Query { greeting(name: String): String }');
const arg = schema.getQueryType().getFields().greeting.args[0];
 
isArgument(arg); // => true
isArgument(schema.getQueryType()); // => false

assertArgument()

Returns the value as a GraphQLArgument, or throws if it is not one.

Signature:

assertArgument(arg: unknown): GraphQLArgument;

Arguments
NameTypeDescription
argunknownValue to inspect.

Returns
TypeDescription
GraphQLArgumentThe value typed as a GraphQLArgument.

Example
import { buildSchema } from 'graphql/utilities';
import { assertArgument } from 'graphql/type';
 
const schema = buildSchema('type Query { greeting(name: String): String }');
const arg = assertArgument(schema.getQueryType().getFields().greeting.args[0]);
 
arg.name; // => 'name'
assertArgument(schema.getQueryType()); // throws an error

isInterfaceType()

Returns true when the value is a GraphQLInterfaceType.

Signature:

isInterfaceType(
  type: unknown,
): type is GraphQLInterfaceType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLInterfaceTypeTrue when the value is a GraphQLInterfaceType.

Example
import { buildSchema } from 'graphql/utilities';
import { isInterfaceType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Query {
    node: Node
  }
`);
 
isInterfaceType(schema.getType('Node')); // => true
isInterfaceType(schema.getType('User')); // => false

assertInterfaceType()

Returns the value as a GraphQLInterfaceType, or throws if it is not one.

Signature:

assertInterfaceType(type: unknown): GraphQLInterfaceType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLInterfaceTypeThe value typed as a GraphQLInterfaceType.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInterfaceType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Query {
    node: Node
  }
`);
 
const nodeType = assertInterfaceType(schema.getType('Node'));
 
nodeType.name; // => 'Node'
assertInterfaceType(schema.getType('User')); // throws an error

isUnionType()

Returns true when the value is a GraphQLUnionType.

Signature:

isUnionType(
  type: unknown,
): type is GraphQLUnionType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLUnionTypeTrue when the value is a GraphQLUnionType.

Example
import { buildSchema } from 'graphql/utilities';
import { isUnionType } from 'graphql/type';
 
const schema = buildSchema(`
  type Photo {
    url: String!
  }
 
  type Video {
    url: String!
  }
 
  union Media = Photo | Video
 
  type Query {
    media: [Media]
  }
`);
 
isUnionType(schema.getType('Media')); // => true
isUnionType(schema.getType('Photo')); // => false

assertUnionType()

Returns the value as a GraphQLUnionType, or throws if it is not one.

Signature:

assertUnionType(type: unknown): GraphQLUnionType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLUnionTypeThe value typed as a GraphQLUnionType.

Example
import { buildSchema } from 'graphql/utilities';
import { assertUnionType } from 'graphql/type';
 
const schema = buildSchema(`
  type Photo {
    url: String!
  }
 
  type Video {
    url: String!
  }
 
  union Media = Photo | Video
 
  type Query {
    media: [Media]
  }
`);
 
const mediaType = assertUnionType(schema.getType('Media'));
 
mediaType.getTypes().map((type) => type.name); // => ['Photo', 'Video']
assertUnionType(schema.getType('Photo')); // throws an error

isEnumType()

Returns true when the value is a GraphQLEnumType.

Signature:

isEnumType(
  type: unknown,
): type is GraphQLEnumType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLEnumTypeTrue when the value is a GraphQLEnumType.

Example
import { buildSchema } from 'graphql/utilities';
import { isEnumType } from 'graphql/type';
 
const schema = buildSchema(`
  enum Episode {
    NEW_HOPE
    EMPIRE
  }
 
  type Query {
    favoriteEpisode: Episode
  }
`);
 
isEnumType(schema.getType('Episode')); // => true
isEnumType(schema.getType('Query')); // => false

assertEnumType()

Returns the value as a GraphQLEnumType, or throws if it is not one.

Signature:

assertEnumType(type: unknown): GraphQLEnumType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLEnumTypeThe value typed as a GraphQLEnumType.

Example
import { buildSchema } from 'graphql/utilities';
import { assertEnumType } from 'graphql/type';
 
const schema = buildSchema(`
  enum Episode {
    NEW_HOPE
    EMPIRE
  }
 
  type Query {
    favoriteEpisode: Episode
  }
`);
 
const episodeType = assertEnumType(schema.getType('Episode'));
 
episodeType.getValues().map((value) => value.name); // => ['NEW_HOPE', 'EMPIRE']
assertEnumType(schema.getType('Query')); // throws an error

isEnumValue()

Returns true when the value is a resolved GraphQL enum value definition.

Signature:

isEnumValue(
  value: unknown,
): value is GraphQLEnumValue;

Arguments
NameTypeDescription
valueunknownValue to inspect.

Returns
TypeDescription
value is GraphQLEnumValueTrue when the value is a GraphQLEnumValue.

Example
import { buildSchema } from 'graphql/utilities';
import { assertEnumType, isEnumValue } from 'graphql/type';
 
const schema = buildSchema('enum Episode { NEW_HOPE } type Query { episode: Episode }');
const enumValue = assertEnumType(schema.getType('Episode')).getValues()[0];
 
isEnumValue(enumValue); // => true
isEnumValue(schema.getType('Episode')); // => false

assertEnumValue()

Returns the value as a GraphQLEnumValue, or throws if it is not one.

Signature:

assertEnumValue(value: unknown): GraphQLEnumValue;

Arguments
NameTypeDescription
valueunknownValue to inspect.

Returns
TypeDescription
GraphQLEnumValueThe value typed as a GraphQLEnumValue.

Example
import { buildSchema } from 'graphql/utilities';
import { assertEnumType, assertEnumValue } from 'graphql/type';
 
const schema = buildSchema('enum Episode { NEW_HOPE } type Query { episode: Episode }');
const enumValue = assertEnumValue(
  assertEnumType(schema.getType('Episode')).getValues()[0],
);
 
enumValue.name; // => 'NEW_HOPE'
assertEnumValue(schema.getType('Episode')); // throws an error

isInputObjectType()

Returns true when the value is a GraphQLInputObjectType.

Signature:

isInputObjectType(
  type: unknown,
): type is GraphQLInputObjectType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLInputObjectTypeTrue when the value is a GraphQLInputObjectType.

Example
import { buildSchema } from 'graphql/utilities';
import { isInputObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type Review {
    stars: Int!
  }
 
  type Query {
    review(input: ReviewInput): Review
  }
`);
 
isInputObjectType(schema.getType('ReviewInput')); // => true
isInputObjectType(schema.getType('Review')); // => false

assertInputObjectType()

Returns the value as a GraphQLInputObjectType, or throws if it is not one.

Signature:

assertInputObjectType(type: unknown): GraphQLInputObjectType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLInputObjectTypeThe value typed as a GraphQLInputObjectType.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInputObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type Review {
    stars: Int!
  }
 
  type Query {
    review(input: ReviewInput): Review
  }
`);
 
const inputType = assertInputObjectType(schema.getType('ReviewInput'));
 
Object.keys(inputType.getFields()); // => ['stars']
assertInputObjectType(schema.getType('Review')); // throws an error

isInputField()

Returns true when the value is a resolved GraphQL input field definition.

Signature:

isInputField(
  field: unknown,
): field is GraphQLInputField;

Arguments
NameTypeDescription
fieldunknownValue to inspect.

Returns
TypeDescription
field is GraphQLInputFieldTrue when the value is a GraphQLInputField.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInputObjectType, isInputField } from 'graphql/type';
 
const schema = buildSchema('input ReviewInput { stars: Int } type Query { ok: Boolean }');
const inputField = assertInputObjectType(schema.getType('ReviewInput')).getFields().stars;
 
isInputField(inputField); // => true
isInputField(schema.getQueryType()); // => false

assertInputField()

Returns the value as a GraphQLInputField, or throws if it is not one.

Signature:

assertInputField(field: unknown): GraphQLInputField;

Arguments
NameTypeDescription
fieldunknownValue to inspect.

Returns
TypeDescription
GraphQLInputFieldThe value typed as a GraphQLInputField.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInputField, assertInputObjectType } from 'graphql/type';
 
const schema = buildSchema('input ReviewInput { stars: Int } type Query { ok: Boolean }');
const inputField = assertInputField(
  assertInputObjectType(schema.getType('ReviewInput')).getFields().stars,
);
 
inputField.name; // => 'stars'
assertInputField(schema.getQueryType()); // throws an error

assertListType()

Returns the value as a GraphQLList, or throws if it is not one.

Signature:

assertListType(
  type: unknown,
): GraphQLList<GraphQLType>;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLList<GraphQLType>The value typed as a GraphQLList.

Example
import { GraphQLList, GraphQLString, assertListType } from 'graphql/type';
 
const listType = assertListType(new GraphQLList(GraphQLString));
 
listType.ofType; // => GraphQLString
assertListType(GraphQLString); // throws an error

assertNonNullType()

Returns the value as a GraphQLNonNull, or throws if it is not one.

Signature:

assertNonNullType(
  type: unknown,
): GraphQLNonNull<GraphQLNullableType>;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLNonNull<GraphQLNullableType>The value typed as a GraphQLNonNull.

Example
import { GraphQLNonNull, GraphQLString, assertNonNullType } from 'graphql/type';
 
const nonNullType = assertNonNullType(new GraphQLNonNull(GraphQLString));
 
nonNullType.ofType; // => GraphQLString
assertNonNullType(GraphQLString); // throws an error

isInputType()

Returns true when the value can be used as a GraphQL input type.

Signature:

isInputType(
  type: unknown,
): type is GraphQLInputType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLInputTypeTrue when the value can be used as a GraphQL input type.

Example
import { buildSchema } from 'graphql/utilities';
import { isInputType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type Review {
    stars: Int!
  }
 
  type Query {
    review(input: ReviewInput): Review
  }
`);
 
isInputType(schema.getType('ReviewInput')); // => true
isInputType(schema.getType('Review')); // => false

assertInputType()

Returns the value as a GraphQL input type, or throws if it is not one.

Signature:

assertInputType(type: unknown): GraphQLInputType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLInputTypeThe value typed as a GraphQL input type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInputType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type Review {
    stars: Int!
  }
 
  type Query {
    review(input: ReviewInput): Review
  }
`);
 
const inputType = assertInputType(schema.getType('ReviewInput'));
 
inputType.toString(); // => 'ReviewInput'
assertInputType(schema.getType('Review')); // throws an error

isOutputType()

Returns true when the value can be used as a GraphQL output type.

Signature:

isOutputType(
  type: unknown,
): type is GraphQLOutputType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLOutputTypeTrue when the value can be used as a GraphQL output type.

Example
import { buildSchema } from 'graphql/utilities';
import { isOutputType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type Review {
    stars: Int!
  }
 
  type Query {
    review(input: ReviewInput): Review
  }
`);
 
isOutputType(schema.getType('Review')); // => true
isOutputType(schema.getType('ReviewInput')); // => false

assertOutputType()

Returns the value as a GraphQL output type, or throws if it is not one.

Signature:

assertOutputType(type: unknown): GraphQLOutputType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLOutputTypeThe value typed as a GraphQL output type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertOutputType } from 'graphql/type';
 
const schema = buildSchema(`
  input ReviewInput {
    stars: Int!
  }
 
  type Review {
    stars: Int!
  }
 
  type Query {
    review(input: ReviewInput): Review
  }
`);
 
const outputType = assertOutputType(schema.getType('Review'));
 
outputType.toString(); // => 'Review'
assertOutputType(schema.getType('ReviewInput')); // throws an error

isLeafType()

Returns true when the value is a GraphQL scalar or enum type.

Signature:

isLeafType(
  type: unknown,
): type is GraphQLLeafType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLLeafTypeTrue when the value is a GraphQL scalar or enum type.

Example
import { buildSchema } from 'graphql/utilities';
import { isLeafType } from 'graphql/type';
 
const schema = buildSchema(`
  enum Episode {
    NEW_HOPE
  }
 
  type Review {
    stars: Int!
  }
 
  type Query {
    episode: Episode
    review: Review
  }
`);
 
isLeafType(schema.getType('Episode')); // => true
isLeafType(schema.getType('String')); // => true
isLeafType(schema.getType('Review')); // => false

assertLeafType()

Returns the value as a GraphQL leaf type, or throws if it is not one.

Signature:

assertLeafType(type: unknown): GraphQLLeafType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLLeafTypeThe value typed as a GraphQL leaf type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertLeafType } from 'graphql/type';
 
const schema = buildSchema(`
  enum Episode {
    NEW_HOPE
  }
 
  type Review {
    stars: Int!
  }
 
  type Query {
    episode: Episode
    review: Review
  }
`);
 
const episodeType = assertLeafType(schema.getType('Episode'));
 
episodeType.toString(); // => 'Episode'
assertLeafType(schema.getType('Review')); // throws an error

isCompositeType()

Returns true when the value is a GraphQL object, interface, or union type.

Signature:

isCompositeType(
  type: unknown,
): type is GraphQLCompositeType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLCompositeTypeTrue when the value is a GraphQL object, interface, or union type.

Example
import { buildSchema } from 'graphql/utilities';
import { isCompositeType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  union SearchResult = User
 
  type Query {
    node: Node
    search: [SearchResult]
  }
`);
 
isCompositeType(schema.getType('User')); // => true
isCompositeType(schema.getType('Node')); // => true
isCompositeType(schema.getType('SearchResult')); // => true
isCompositeType(schema.getType('String')); // => false

assertCompositeType()

Returns the value as a GraphQL composite type, or throws if it is not one.

Signature:

assertCompositeType(type: unknown): GraphQLCompositeType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLCompositeTypeThe value typed as a GraphQL composite type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertCompositeType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Query {
    node: Node
  }
`);
 
const userType = assertCompositeType(schema.getType('User'));
 
userType.toString(); // => 'User'
assertCompositeType(schema.getType('String')); // throws an error

isAbstractType()

Returns true when the value is a GraphQL interface or union type.

Signature:

isAbstractType(
  type: unknown,
): type is GraphQLAbstractType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLAbstractTypeTrue when the value is a GraphQL interface or union type.

Example
import { buildSchema } from 'graphql/utilities';
import { isAbstractType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  union SearchResult = User
 
  type Query {
    node: Node
    search: [SearchResult]
  }
`);
 
isAbstractType(schema.getType('Node')); // => true
isAbstractType(schema.getType('SearchResult')); // => true
isAbstractType(schema.getType('User')); // => false

assertAbstractType()

Returns the value as a GraphQL abstract type, or throws if it is not one.

Signature:

assertAbstractType(type: unknown): GraphQLAbstractType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLAbstractTypeThe value typed as a GraphQL abstract type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertAbstractType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Query {
    node: Node
  }
`);
 
const nodeType = assertAbstractType(schema.getType('Node'));
 
nodeType.toString(); // => 'Node'
assertAbstractType(schema.getType('User')); // throws an error

isWrappingType()

Returns true when the value is a GraphQL list or non-null wrapper type.

Signature:

isWrappingType(
  type: unknown,
): type is GraphQLWrappingType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLWrappingTypeTrue when the value is a GraphQL list or non-null wrapper type.

Example
import {
  GraphQLList,
  GraphQLNonNull,
  GraphQLString,
  isWrappingType,
} from 'graphql/type';
 
isWrappingType(new GraphQLList(GraphQLString)); // => true
isWrappingType(new GraphQLNonNull(GraphQLString)); // => true
isWrappingType(GraphQLString); // => false

assertWrappingType()

Returns the value as a GraphQL wrapping type, or throws if it is not one.

Signature:

assertWrappingType(type: unknown): GraphQLWrappingType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLWrappingTypeThe value typed as a GraphQL wrapping type.

Example
import { GraphQLList, GraphQLString, assertWrappingType } from 'graphql/type';
 
const wrappingType = assertWrappingType(new GraphQLList(GraphQLString));
 
wrappingType.toString(); // => '[String]'
assertWrappingType(GraphQLString); // throws an error

isNullableType()

Returns true when the value is a GraphQL type that can accept null.

Signature:

isNullableType(
  type: unknown,
): type is GraphQLNullableType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLNullableTypeTrue when the value is a GraphQL type that can accept null.

Example
import { GraphQLNonNull, GraphQLString, isNullableType } from 'graphql/type';
 
isNullableType(GraphQLString); // => true
isNullableType(new GraphQLNonNull(GraphQLString)); // => false
isNullableType(null); // => false

assertNullableType()

Returns the value as a nullable GraphQL type, or throws if it is not one.

Signature:

assertNullableType(type: unknown): GraphQLNullableType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLNullableTypeThe value typed as a nullable GraphQL type.

Example
import {
  GraphQLNonNull,
  GraphQLString,
  assertNullableType,
} from 'graphql/type';
 
const nullableType = assertNullableType(GraphQLString);
 
nullableType; // => GraphQLString
assertNullableType(new GraphQLNonNull(GraphQLString)); // throws an error

isNamedType()

Returns true when the value is a GraphQL named type.

Signature:

isNamedType(
  type: unknown,
): type is GraphQLNamedType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
type is GraphQLNamedTypeTrue when the value is a GraphQL named type.

Example
import { GraphQLList, GraphQLString, isNamedType } from 'graphql/type';
 
isNamedType(GraphQLString); // => true
isNamedType(new GraphQLList(GraphQLString)); // => false
isNamedType(null); // => false

assertNamedType()

Returns the value as a GraphQL named type, or throws if it is not one.

Signature:

assertNamedType(type: unknown): GraphQLNamedType;

Arguments
NameTypeDescription
typeunknownThe GraphQL type to inspect.

Returns
TypeDescription
GraphQLNamedTypeThe value typed as a GraphQL named type.

Example
import { GraphQLList, GraphQLString, assertNamedType } from 'graphql/type';
 
const namedType = assertNamedType(GraphQLString);
 
namedType.name; // => 'String'
assertNamedType(new GraphQLList(GraphQLString)); // throws an error

resolveReadonlyArrayThunk()

Resolves a thunked readonly array.


Type Parameters
NameConstraintDefaultDescription
TThe element type resolved from the thunk or array.

Signature:

resolveReadonlyArrayThunk<T>(
  thunk: ThunkReadonlyArray<T>,
): readonly T[];

Arguments
NameTypeDescription
thunkThunkReadonlyArray<T>The thunk or value to resolve.

Returns
TypeDescription
readonly T[]The resolved readonly array.

Example
import { GraphQLString, resolveReadonlyArrayThunk } from 'graphql/type';
 
const lazyFields = resolveReadonlyArrayThunk(() => [GraphQLString]);
const fields = resolveReadonlyArrayThunk([GraphQLString]);
 
lazyFields; // => [GraphQLString]
fields; // => [GraphQLString]

resolveObjMapThunk()

Resolves a thunked object map.


Type Parameters
NameConstraintDefaultDescription
TThe object-map value type resolved from the thunk or map.

Signature:

resolveObjMapThunk<T>(
  thunk: ThunkObjMap<T>,
): ObjMap<T>;

Arguments
NameTypeDescription
thunkThunkObjMap<T>The thunk or value to resolve.

Returns
TypeDescription
ObjMap<T>The resolved object map.

Example
import { GraphQLString, resolveObjMapThunk } from 'graphql/type';
 
const lazyFields = resolveObjMapThunk(() => ({ name: GraphQLString }));
const fields = resolveObjMapThunk({ name: GraphQLString });
 
lazyFields.name; // => GraphQLString
fields.name; // => GraphQLString

isRequiredArgument()

Returns true when the argument is non-null and has no default value.

Signature:

isRequiredArgument(
  arg: GraphQLArgument | GraphQLVariableSignature,
): boolean;

Arguments
NameTypeDescription
argGraphQLArgument | GraphQLVariableSignatureThe argument definition to inspect.

Returns
TypeDescription
booleanTrue when the argument is non-null and has no default value.

Example
import {
  GraphQLArgument,
  GraphQLField,
  GraphQLInt,
  GraphQLNonNull,
  GraphQLObjectType,
  GraphQLString,
  isRequiredArgument,
} from 'graphql/type';
 
const Query = new GraphQLObjectType({ name: 'Query', fields: {} });
const field = new GraphQLField(Query, 'reviews', { type: GraphQLString });
const requiredArgument = new GraphQLArgument(field, 'id', {
  type: new GraphQLNonNull(GraphQLInt),
});
const optionalArgument = new GraphQLArgument(field, 'name', {
  type: GraphQLString,
});
const argumentWithDefault = new GraphQLArgument(field, 'limit', {
  type: new GraphQLNonNull(GraphQLInt),
  default: { value: 10 },
});
 
isRequiredArgument(requiredArgument); // => true
isRequiredArgument(optionalArgument); // => false
isRequiredArgument(argumentWithDefault); // => false

isRequiredInputField()

Returns true when the input field is non-null and has no default value.

Signature:

isRequiredInputField(field: GraphQLInputField): boolean;

Arguments
NameTypeDescription
fieldGraphQLInputFieldThe input field definition to inspect.

Returns
TypeDescription
booleanTrue when the input field is non-null and has no default value.

Example
import {
  GraphQLInputField,
  GraphQLInputObjectType,
  GraphQLInt,
  GraphQLNonNull,
  GraphQLString,
  isRequiredInputField,
} from 'graphql/type';
 
const ReviewInput = new GraphQLInputObjectType({
  name: 'ReviewInput',
  fields: {},
});
const requiredField = new GraphQLInputField(ReviewInput, 'id', {
  type: new GraphQLNonNull(GraphQLInt),
});
const optionalField = new GraphQLInputField(ReviewInput, 'name', {
  type: GraphQLString,
});
const fieldWithDefault = new GraphQLInputField(ReviewInput, 'limit', {
  type: new GraphQLNonNull(GraphQLInt),
  default: { value: 10 },
});
 
isRequiredInputField(requiredField); // => true
isRequiredInputField(optionalField); // => false
isRequiredInputField(fieldWithDefault); // => false

Types

GraphQLType

Type alias. These are all of the possible kinds of types.

type GraphQLType = GraphQLNamedType | GraphQLWrappingType;

GraphQLNullableInputType

Type alias. These types may be used as input types for arguments and directives.

type GraphQLNullableInputType =
  | GraphQLNamedInputType
  | GraphQLList<GraphQLInputType>;

GraphQLInputType

Type alias. These types may be used as input types for arguments and directives.

type GraphQLInputType =
  | GraphQLNullableInputType
  | GraphQLNonNull<GraphQLNullableInputType>;

GraphQLNullableOutputType

Type alias. These types may be used as output types as the result of fields.

type GraphQLNullableOutputType =
  | GraphQLNamedOutputType
  | GraphQLList<GraphQLOutputType>;

GraphQLOutputType

Type alias. These types may be used as output types as the result of fields.

type GraphQLOutputType =
  | GraphQLNullableOutputType
  | GraphQLNonNull<GraphQLNullableOutputType>;

GraphQLLeafType

Type alias. These types may describe types which may be leaf values.

type GraphQLLeafType = GraphQLScalarType | GraphQLEnumType;

GraphQLCompositeType

Type alias. These types may describe the parent context of a selection set.

type GraphQLCompositeType =
  | GraphQLObjectType
  | GraphQLInterfaceType
  | GraphQLUnionType;

GraphQLAbstractType

Type alias. These types may describe the parent context of a selection set.

type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType;

GraphQLWrappingType

Type alias. These types wrap and modify other types

type GraphQLWrappingType =
  | GraphQLList<GraphQLType>
  | GraphQLNonNull<GraphQLNullableType>;

GraphQLNullableType

Type alias. These types can all accept null as a value.

type GraphQLNullableType =
  | GraphQLNamedType
  | GraphQLList<GraphQLType>;

GraphQLNamedType

Type alias. These named types do not include modifiers like List or NonNull.

type GraphQLNamedType = GraphQLNamedInputType | GraphQLNamedOutputType;

GraphQLNamedInputType

Type alias. A named GraphQL type that can be used as an input type.

type GraphQLNamedInputType =
  | GraphQLScalarType
  | GraphQLEnumType
  | GraphQLInputObjectType;

GraphQLNamedOutputType

Type alias. A named GraphQL type that can be used as an output type.

type GraphQLNamedOutputType =
  | GraphQLScalarType
  | GraphQLObjectType
  | GraphQLInterfaceType
  | GraphQLUnionType
  | GraphQLEnumType;

ThunkReadonlyArray

Type alias. Used while defining GraphQL types to allow for circular references in otherwise immutable type definitions.


Type Parameters
NameConstraintDefaultDescription
TThe element type returned by the thunk or array.
type ThunkReadonlyArray<T> =
  | (() => ReadonlyArray<T>)
  | ReadonlyArray<T>;

ThunkObjMap

Type alias. A thunk that resolves to an object map.


Type Parameters
NameConstraintDefaultDescription
TValue type stored in the object map.
type ThunkObjMap<T> =
  | (() => ObjMap<T>)
  | ObjMap<T>;

GraphQLScalarTypeExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLScalarSerializer Deprecated

Type alias. Deprecated function type that serializes a runtime value as a scalar output value. Use GraphQLScalarOutputValueCoercer instead.


Type Parameters
NameConstraintDefaultDescription
TExternalExternal representation accepted from or returned to callers.
type GraphQLScalarSerializer<TExternal> = (
  outputValue: unknown,
) => TExternal;

GraphQLScalarOutputValueCoercer

Type alias. Function used to coerce internal scalar values for response output.


Type Parameters
NameConstraintDefaultDescription
TExternalExternal representation accepted from or returned to callers.
type GraphQLScalarOutputValueCoercer<TExternal> = (
  outputValue: unknown,
) => TExternal;

GraphQLScalarValueParser Deprecated

Type alias. Deprecated function type that parses a runtime input value as a scalar input value. Use GraphQLScalarInputValueCoercer instead.


Type Parameters
NameConstraintDefaultDescription
TInternalInternal runtime representation for this scalar.
type GraphQLScalarValueParser<TInternal> = (
  inputValue: unknown,
) => TInternal;

GraphQLScalarInputValueCoercer

Type alias. Function used to coerce externally provided scalar input values.


Type Parameters
NameConstraintDefaultDescription
TInternalInternal runtime representation for this scalar.
type GraphQLScalarInputValueCoercer<TInternal> = (
  inputValue: unknown,
) => TInternal;

GraphQLScalarLiteralParser Deprecated

Type alias. Deprecated function type that parses a GraphQL value literal as a scalar input value. Use GraphQLScalarInputLiteralCoercer instead.


Type Parameters
NameConstraintDefaultDescription
TInternalInternal runtime representation for this scalar.
type GraphQLScalarLiteralParser<TInternal> = (
  valueNode: ValueNode,
  variables: Maybe<ObjMap<unknown>>,
) => Maybe<TInternal>;

GraphQLScalarInputLiteralCoercer

Type alias. Function used to coerce GraphQL scalar input literals.


Type Parameters
NameConstraintDefaultDescription
TInternalInternal runtime representation for this scalar.
type GraphQLScalarInputLiteralCoercer<TInternal> = (
  valueNode: ConstValueNode,
) => Maybe<TInternal>;

GraphQLScalarTypeConfig

Interface. Configuration used to construct a GraphQLScalarType.


Type Parameters
NameConstraintDefaultDescription
TInternalInternal runtime representation for this scalar.
TExternalExternal representation accepted from or returned to callers.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
description?Maybe<string>Human-readable description for this schema element, if provided.
specifiedByURL?Maybe<string>URL identifying the behavior specified for this custom scalar.
serialize?GraphQLScalarSerializer<TExternal>Deprecated legacy serializer used to convert internal values for response
output. Use coerceOutputValue() instead.
parseValue?GraphQLScalarValueParser<TInternal>Deprecated legacy parser used to convert externally provided input values.
Use coerceInputValue() instead.
parseLiteral?GraphQLScalarLiteralParser<TInternal>Deprecated legacy parser used to convert externally provided input
literals. Use replaceVariables() and coerceInputLiteral() instead.
coerceOutputValue?GraphQLScalarOutputValueCoercer<TExternal>Coerces an internal value to include in a response.
coerceInputValue?GraphQLScalarInputValueCoercer<TInternal>Coerces an externally provided value to use as an input.
coerceInputLiteral?GraphQLScalarInputLiteralCoercer<TInternal>Coerces an externally provided const literal value to use as an input.
valueToLiteral?GraphQLScalarValueToLiteralTranslates an externally provided value to a literal (AST).
extensions?Maybe<Readonly<GraphQLScalarTypeExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<ScalarTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodes?Maybe<readonly ScalarTypeExtensionNode[]>AST extension nodes applied to this schema element.

GraphQLObjectTypeExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need. We’ve provided these template arguments because this is an open type and you may find them useful.


Type Parameters
NameConstraintDefaultDescription
_TSourceanyReserved source type parameter for extension typing.
_TContextanyReserved context type parameter for extension typing.

GraphQLObjectTypeConfig

Interface. Configuration used to construct a GraphQLObjectType.


Type Parameters
NameConstraintDefaultDescription
TSourceSource object type passed to resolvers.
TContextContext object type passed to resolvers.
TAbstractunknownRuntime value type used for abstract type resolution.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
description?Maybe<string>Human-readable description for this schema element, if provided.
interfaces?ThunkReadonlyArray<GraphQLInterfaceType>Interfaces implemented by this object or interface type.
fieldsThunkObjMap< GraphQLFieldConfig<TSource, TContext> >Fields declared by this object, interface, input object, or literal.
isTypeOf?Maybe< GraphQLIsTypeOfFn<TAbstract, TContext> >Predicate used to determine whether a runtime value belongs to this object type.
extensions?Maybe< Readonly< GraphQLObjectTypeExtensions<TSource, TContext> > >Extension fields to include in the formatted result.
astNode?Maybe<ObjectTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodes?Maybe<readonly ObjectTypeExtensionNode[]>AST extension nodes applied to this schema element.

GraphQLTypeResolver

Type alias. Resolves the concrete object type for an abstract GraphQL type.


Type Parameters
NameConstraintDefaultDescription
TSourceSource object type passed to resolvers.
TContextContext object type passed to resolvers.
type GraphQLTypeResolver<TSource, TContext> = (
  value: TSource,
  context: TContext,
  info: GraphQLResolveInfo,
  abstractType: GraphQLAbstractType,
) => PromiseOrValue<string | undefined>;

GraphQLIsTypeOfFn

Type alias. Checks whether a runtime value belongs to a GraphQL object type.


Type Parameters
NameConstraintDefaultDescription
TAbstractRuntime value type used for abstract type resolution.
TContextContext object type passed to resolvers.
type GraphQLIsTypeOfFn<TAbstract, TContext> = (
  value: TAbstract,
  context: TContext,
  info: GraphQLResolveInfo,
) => PromiseOrValue<boolean>;

GraphQLFieldResolver

Type alias. Resolves the runtime value for a GraphQL field.


Type Parameters
NameConstraintDefaultDescription
TSourceSource object type passed to resolvers.
TContextContext object type passed to resolvers.
TArgsanyArgument object type passed to resolvers.
TResultunknownResult value type.
type GraphQLFieldResolver<
  TSource,
  TContext,
  TArgs = any,
  TResult = unknown,
> = (
  source: TSource,
  args: TArgs,
  context: TContext,
  info: GraphQLResolveInfo,
) => TResult;

GraphQLResolveInfoHelpers

Interface. Utilities available from resolver info for tracking asynchronous work.


Members
NameTypeDescription
promiseAll( values: readonly ( | T | PromiseLike<T> )[], ) => Promise<T[]>Promise.all wrapper that allows rejected branches to be tracked
as execution async work.
Intended use: return or await this promise from resolver work.
Un-awaited async side effects are an anti-pattern:
const { promiseAll } = info.getAsyncHelpers();
promiseAll([someAsyncWork(), someOtherAsyncWork()]).catch(() => undefined);
In that anti-pattern, tracking starts only after rejection (on a
later microtask), so this work is not guaranteed to delay
hooks.asyncWorkFinished.
Use track(...) for un-awaited async side effects:
const { track } = info.getAsyncHelpers();
track([
someAsyncWork().catch(() => undefined),
someOtherAsyncWork().catch(() => undefined)
]);
track(maybePromises: readonly unknown[]) => voidTracks asynchronous work that should delay execution completion hooks.

GraphQLResolveInfo

Interface. Information about the currently executing GraphQL field.


Members
NameTypeDescription
fieldNamestringThe field name referenced by this schema coordinate.
fieldNodesreadonly FieldNode[]AST field nodes that contributed to the current field execution.
returnTypeGraphQLOutputTypeGraphQL output type declared for the current field.
parentTypeGraphQLObjectTypeObject type that owns the current field.
pathPathResponse path where this error occurred during execution.
schemaGraphQLSchemaThe schema used for validation or execution.
fragmentsObjMap<FragmentDefinitionNode>Fragment definitions in the operation document keyed by fragment name.
rootValueunknownInitial root value passed to the operation.
operationOperationDefinitionNodeThe operation selected for execution.
variableValuesVariableValuesCoerced variable values and source metadata for this operation. Resolver
code that needs runtime variable values should read variableValues.coerced.
getAbortSignal() => anyReturns the AbortSignal supplied for this execution, if any.
getAsyncHelpers() => GraphQLResolveInfoHelpersReturns helper functions for tracking asynchronous resolver work.

GraphQLFieldExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need. We’ve provided these template arguments because this is an open type and you may find them useful.


Type Parameters
NameConstraintDefaultDescription
_TSourceReserved source type parameter for extension typing.
_TContextReserved context type parameter for extension typing.
_TArgsanyReserved argument type parameter for extension typing.

GraphQLFieldConfig

Interface. Configuration used to define a GraphQL field.


Type Parameters
NameConstraintDefaultDescription
TSourceSource object type passed to resolvers.
TContextContext object type passed to resolvers.
TArgsanyArgument object type passed to resolvers.

Members
NameTypeDescription
description?Maybe<string>Human-readable description for this schema element, if provided.
typeGraphQLOutputTypeThe GraphQL type reference or runtime type for this element.
args?GraphQLFieldConfigArgumentMapArguments accepted by this field or directive.
resolve?GraphQLFieldResolver< TSource, TContext, TArgs >Resolver function used to produce this field value.
subscribe?GraphQLFieldResolver< TSource, TContext, TArgs >Resolver function used to create a subscription event stream for this field.
deprecationReason?Maybe<string>Reason this element is deprecated, if one was provided.
extensions?Maybe< Readonly< GraphQLFieldExtensions< TSource, TContext, TArgs > > >Extension fields to include in the formatted result.
astNode?Maybe<FieldDefinitionNode>AST node from which this schema element was built, if available.

GraphQLFieldConfigArgumentMap

Type alias. A map of argument names to argument configuration objects.

type GraphQLFieldConfigArgumentMap = ObjMap<GraphQLArgumentConfig>;

GraphQLArgumentExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLArgumentConfig

Interface. Configuration used to define a GraphQL argument.


Members
NameTypeDescription
description?Maybe<string>Human-readable description for this schema element, if provided.
typeGraphQLInputTypeThe GraphQL type reference or runtime type for this element.
defaultValue?unknownDeprecated legacy default value for this argument. Use default instead.
default?GraphQLDefaultInputDefault value represented as either a runtime value or a GraphQL literal.
deprecationReason?Maybe<string>Reason this element is deprecated, if one was provided.
extensions?Maybe<Readonly<GraphQLArgumentExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<InputValueDefinitionNode>AST node from which this schema element was built, if available.

GraphQLFieldConfigMap

Type alias. A map of field names to field configuration objects.


Type Parameters
NameConstraintDefaultDescription
TSourceSource object type passed to resolvers.
TContextContext object type passed to resolvers.
type GraphQLFieldConfigMap<TSource, TContext> =
  ObjMap<
    GraphQLFieldConfig<TSource, TContext>
  >;

GraphQLField

Interface. A resolved GraphQL field definition.


Type Parameters
NameConstraintDefaultDescription
TSourceanySource object type passed to resolvers.
TContextanyContext object type passed to resolvers.
TArgsanyArgument object type passed to resolvers.

Members
NameTypeDescription
parentType| GraphQLObjectType<TSource, TContext> | GraphQLInterfaceType<TSource, TContext> | undefinedObject or interface type that owns this field, if known.
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
typeGraphQLOutputTypeThe GraphQL type reference or runtime type for this element.
argsreadonly GraphQLArgument[]Arguments accepted by this field or directive.
resolve?GraphQLFieldResolver< TSource, TContext, TArgs >Resolver function used to produce this field value.
subscribe?GraphQLFieldResolver< TSource, TContext, TArgs >Resolver function used to create a subscription event stream for this field.
deprecationReasonMaybe<string>Reason this element is deprecated, if one was provided.
extensionsReadonly< GraphQLFieldExtensions< TSource, TContext, TArgs > >Extension fields to include in the formatted result.
astNodeMaybe<FieldDefinitionNode>AST node from which this schema element was built, if available.

toConfig()

Returns a normalized configuration object for this field.

Signature:

toConfig(): GraphQLFieldNormalizedConfig<
  TSource,
  TContext,
  TArgs
>;

Returns
TypeDescription
GraphQLFieldNormalizedConfig< TSource, TContext, TArgs >A configuration object that can be used to recreate this field.

Example
import { GraphQLField, GraphQLObjectType, GraphQLString } from 'graphql/type';
 
const Query = new GraphQLObjectType({ name: 'Query', fields: {} });
const field = new GraphQLField(Query, 'greeting', {
  type: GraphQLString,
  extensions: { cacheSeconds: 60 },
});
 
field.toConfig().type; // => GraphQLString
field.toConfig().extensions; // => { cacheSeconds: 60 }

toString()

Returns this field as a schema coordinate string.

Signature:

toString(): string;

Returns
TypeDescription
stringThe field coordinate.

Example
import { GraphQLField, GraphQLObjectType, GraphQLString } from 'graphql/type';
 
const Query = new GraphQLObjectType({ name: 'Query', fields: {} });
const field = new GraphQLField(Query, 'greeting', { type: GraphQLString });
 
field.toString(); // => 'Query.greeting'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe field coordinate.

Example
import { GraphQLField, GraphQLObjectType, GraphQLString } from 'graphql/type';
 
const Query = new GraphQLObjectType({ name: 'Query', fields: {} });
const field = new GraphQLField(Query, 'greeting', { type: GraphQLString });
 
JSON.stringify(field); // => '"Query.greeting"'

GraphQLArgument

Interface. A resolved GraphQL argument definition.


Members
NameTypeDescription
parentGraphQLDirective | GraphQLFieldField or directive that owns this argument.
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
typeGraphQLInputTypeThe GraphQL type reference or runtime type for this element.
defaultValueunknownDeprecated legacy default value used when no explicit value is supplied.
Use default instead.
defaultGraphQLDefaultInput | undefinedDefault value represented as either a runtime value or a GraphQL literal.
deprecationReasonMaybe<string>Reason this element is deprecated, if one was provided.
extensionsReadonly<GraphQLArgumentExtensions>Extension fields to include in the formatted result.
astNodeMaybe<InputValueDefinitionNode>AST node from which this schema element was built, if available.

toConfig()

Returns a normalized configuration object for this argument.

Signature:

toConfig(): GraphQLArgumentNormalizedConfig;

Returns
TypeDescription
GraphQLArgumentNormalizedConfigA configuration object that can be used to recreate this argument.

Example
import {
  GraphQLArgument,
  GraphQLField,
  GraphQLObjectType,
  GraphQLString,
} from 'graphql/type';
 
const Query = new GraphQLObjectType({ name: 'Query', fields: {} });
const field = new GraphQLField(Query, 'greeting', { type: GraphQLString });
const arg = new GraphQLArgument(field, 'name', {
  type: GraphQLString,
  default: { value: 'world' },
});
 
arg.toConfig().default.value; // => 'world'

toString()

Returns this argument as a schema coordinate string.

Signature:

toString(): string;

Returns
TypeDescription
stringThe argument coordinate.

Example
import {
  GraphQLArgument,
  GraphQLField,
  GraphQLObjectType,
  GraphQLString,
} from 'graphql/type';
 
const Query = new GraphQLObjectType({ name: 'Query', fields: {} });
const field = new GraphQLField(Query, 'greeting', { type: GraphQLString });
const arg = new GraphQLArgument(field, 'name', { type: GraphQLString });
 
arg.toString(); // => 'Query.greeting(name:)'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe argument coordinate.

Example
import {
  GraphQLArgument,
  GraphQLField,
  GraphQLObjectType,
  GraphQLString,
} from 'graphql/type';
 
const Query = new GraphQLObjectType({ name: 'Query', fields: {} });
const field = new GraphQLField(Query, 'greeting', { type: GraphQLString });
const arg = new GraphQLArgument(field, 'name', { type: GraphQLString });
 
JSON.stringify(arg); // => '"Query.greeting(name:)"'

GraphQLFieldMap

Type alias. A map of field names to resolved field definitions.


Type Parameters
NameConstraintDefaultDescription
TSourceSource object type passed to resolvers.
TContextContext object type passed to resolvers.
type GraphQLFieldMap<TSource, TContext> =
  ObjMap<
    GraphQLField<TSource, TContext>
  >;

GraphQLDefaultInput

Type alias. Default input represented as either a runtime value or a GraphQL literal.

type GraphQLDefaultInput =
  | { value: unknown; literal?: never }
  | { literal: ConstValueNode; value?: never };

GraphQLInterfaceTypeExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLInterfaceTypeConfig

Interface. Configuration used to construct a GraphQLInterfaceType.


Type Parameters
NameConstraintDefaultDescription
TSourceSource object type passed to resolvers.
TContextContext object type passed to resolvers.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
description?Maybe<string>Human-readable description for this schema element, if provided.
interfaces?ThunkReadonlyArray<GraphQLInterfaceType>Interfaces implemented by this object or interface type.
fieldsThunkObjMap< GraphQLFieldConfig<TSource, TContext> >Fields declared by this object, interface, input object, or literal.
resolveType?Maybe< GraphQLTypeResolver<TSource, TContext> >Optionally provide a custom type resolver function. If one is not provided,
the default implementation will call isTypeOf on each implementing
Object type.
extensions?Maybe<Readonly<GraphQLInterfaceTypeExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<InterfaceTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodes?Maybe<readonly InterfaceTypeExtensionNode[]>AST extension nodes applied to this schema element.

GraphQLUnionTypeExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLUnionTypeConfig

Interface. Configuration used to construct a GraphQLUnionType.


Type Parameters
NameConstraintDefaultDescription
TSourceSource object type passed to resolvers.
TContextContext object type passed to resolvers.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
description?Maybe<string>Human-readable description for this schema element, if provided.
typesThunkReadonlyArray<GraphQLObjectType>Object types that belong to this union type.
resolveType?Maybe< GraphQLTypeResolver<TSource, TContext> >Optionally provide a custom type resolver function. If one is not provided,
the default implementation will call isTypeOf on each implementing
Object type.
extensions?Maybe<Readonly<GraphQLUnionTypeExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<UnionTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodes?Maybe<readonly UnionTypeExtensionNode[]>AST extension nodes applied to this schema element.

GraphQLEnumTypeExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLEnumTypeConfig

Interface. Configuration used to construct a GraphQLEnumType.


Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
description?Maybe<string>Human-readable description for this schema element, if provided.
valuesThunkObjMap<GraphQLEnumValueConfig>Values contained in this enum, list, or input-object definition.
extensions?Maybe<Readonly<GraphQLEnumTypeExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<EnumTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodes?Maybe<readonly EnumTypeExtensionNode[]>AST extension nodes applied to this schema element.

GraphQLEnumValueConfigMap

Type alias. A map of enum value names to enum value configuration objects.

type GraphQLEnumValueConfigMap = ObjMap<GraphQLEnumValueConfig>;

GraphQLEnumValueExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLEnumValueConfig

Interface. Configuration used to define a GraphQL enum value.


Members
NameTypeDescription
description?Maybe<string>Human-readable description for this schema element, if provided.
value?anyParsed value represented by this node.
deprecationReason?Maybe<string>Reason this element is deprecated, if one was provided.
extensions?Maybe<Readonly<GraphQLEnumValueExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<EnumValueDefinitionNode>AST node from which this schema element was built, if available.

GraphQLEnumValue

Interface. A resolved GraphQL enum value definition.


Members
NameTypeDescription
parentEnumGraphQLEnumTypeEnum type that owns this enum value.
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
valueanyParsed value represented by this node.
deprecationReasonMaybe<string>Reason this element is deprecated, if one was provided.
extensionsReadonly<GraphQLEnumValueExtensions>Extension fields to include in the formatted result.
astNodeMaybe<EnumValueDefinitionNode>AST node from which this schema element was built, if available.

toConfig()

Returns a normalized configuration object for this enum value.

Signature:

toConfig(): GraphQLEnumValueNormalizedConfig;

Returns
TypeDescription
GraphQLEnumValueNormalizedConfigA configuration object that can be used to recreate this enum value.

Example
import { GraphQLEnumType, GraphQLEnumValue } from 'graphql/type';
 
const Episode = new GraphQLEnumType({
  name: 'Episode',
  values: { NEW_HOPE: { value: 4 } },
});
const enumValue = new GraphQLEnumValue(Episode, 'EMPIRE', {
  value: 5,
  extensions: { trilogy: 'original' },
});
 
enumValue.toConfig(); // => { description: undefined, value: 5, deprecationReason: undefined, extensions: { trilogy: 'original' }, astNode: undefined }

toString()

Returns this enum value as a schema coordinate string.

Signature:

toString(): string;

Returns
TypeDescription
stringEnum value coordinate.

Example
import { GraphQLEnumType, GraphQLEnumValue } from 'graphql/type';
 
const Episode = new GraphQLEnumType({
  name: 'Episode',
  values: { NEW_HOPE: { value: 4 } },
});
const enumValue = new GraphQLEnumValue(Episode, 'EMPIRE', { value: 5 });
 
enumValue.toString(); // => 'Episode.EMPIRE'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringEnum value coordinate.

Example
import { GraphQLEnumType, GraphQLEnumValue } from 'graphql/type';
 
const Episode = new GraphQLEnumType({
  name: 'Episode',
  values: { NEW_HOPE: { value: 4 } },
});
const enumValue = new GraphQLEnumValue(Episode, 'EMPIRE', { value: 5 });
 
JSON.stringify(enumValue); // => '"Episode.EMPIRE"'

GraphQLInputObjectTypeExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLInputObjectTypeConfig

Interface. Configuration used to construct a GraphQLInputObjectType.


Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
description?Maybe<string>Human-readable description for this schema element, if provided.
fieldsThunkObjMap<GraphQLInputFieldConfig>Fields declared by this object, interface, input object, or literal.
extensions?Maybe<Readonly<GraphQLInputObjectTypeExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<InputObjectTypeDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodes?Maybe<readonly InputObjectTypeExtensionNode[]>AST extension nodes applied to this schema element.
isOneOf?booleanWhether this input object uses the experimental OneOf input object semantics.

GraphQLInputFieldExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLInputFieldConfig

Interface. Configuration used to define a GraphQL input field.


Members
NameTypeDescription
description?Maybe<string>Human-readable description for this schema element, if provided.
typeGraphQLInputTypeThe GraphQL type reference or runtime type for this element.
defaultValue?unknownDeprecated legacy default value for this input field. Use default
instead.
default?GraphQLDefaultInputDefault value represented as either a runtime value or a GraphQL literal.
deprecationReason?Maybe<string>Reason this element is deprecated, if one was provided.
extensions?Maybe<Readonly<GraphQLInputFieldExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<InputValueDefinitionNode>AST node from which this schema element was built, if available.

GraphQLInputFieldConfigMap

Type alias. A map of input field names to input field configuration objects.

type GraphQLInputFieldConfigMap = ObjMap<GraphQLInputFieldConfig>;

GraphQLInputField

Interface. A resolved GraphQL input field definition.


Members
NameTypeDescription
parentTypeGraphQLInputObjectTypeInput object type that owns this input field.
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
typeGraphQLInputTypeThe GraphQL type reference or runtime type for this element.
defaultValueunknownDeprecated legacy default value used when no explicit value is supplied.
Use default instead.
defaultGraphQLDefaultInput | undefinedDefault value represented as either a runtime value or a GraphQL literal.
deprecationReasonMaybe<string>Reason this element is deprecated, if one was provided.
extensionsReadonly<GraphQLInputFieldExtensions>Extension fields to include in the formatted result.
astNodeMaybe<InputValueDefinitionNode>AST node from which this schema element was built, if available.

toConfig()

Returns a normalized configuration object for this input field.

Signature:

toConfig(): GraphQLInputFieldNormalizedConfig;

Returns
TypeDescription
GraphQLInputFieldNormalizedConfigA configuration object that can be used to recreate this input field.

Example
import { GraphQLInputField, GraphQLInputObjectType, GraphQLString } from 'graphql/type';
 
const ReviewInput = new GraphQLInputObjectType({
  name: 'ReviewInput',
  fields: {},
});
const field = new GraphQLInputField(ReviewInput, 'commentary', {
  type: GraphQLString,
  extensions: { form: 'review' },
});
 
field.toConfig().extensions; // => { form: 'review' }

toString()

Returns this input field as a schema coordinate string.

Signature:

toString(): string;

Returns
TypeDescription
stringThe input field coordinate.

Example
import { GraphQLInputField, GraphQLInputObjectType, GraphQLString } from 'graphql/type';
 
const ReviewInput = new GraphQLInputObjectType({
  name: 'ReviewInput',
  fields: {},
});
const field = new GraphQLInputField(ReviewInput, 'commentary', {
  type: GraphQLString,
});
 
field.toString(); // => 'ReviewInput.commentary'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe input field coordinate.

Example
import { GraphQLInputField, GraphQLInputObjectType, GraphQLString } from 'graphql/type';
 
const ReviewInput = new GraphQLInputObjectType({
  name: 'ReviewInput',
  fields: {},
});
const field = new GraphQLInputField(ReviewInput, 'commentary', {
  type: GraphQLString,
});
 
JSON.stringify(field); // => '"ReviewInput.commentary"'

GraphQLInputFieldMap

Type alias. A map of input field names to resolved input field definitions.

type GraphQLInputFieldMap = ObjMap<GraphQLInputField>;

Category: Directives

Classes

GraphQLDirective

Directives are used by the GraphQL runtime as a way of modifying execution behavior. Type system creators will usually not create these directly.


Constructor

Creates a GraphQLDirective instance.

Signature:

new GraphQLDirective(config: Readonly<GraphQLDirectiveConfig>);

Arguments
NameTypeDescription
configReadonly<GraphQLDirectiveConfig>Configuration describing this object.

Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
descriptionMaybe<string>Human-readable description for this schema element, if provided.
locationsreadonly DirectiveLocation[]Locations where this directive may be applied.
argsreadonly GraphQLArgument[]Arguments accepted by this field or directive.
isRepeatablebooleanWhether this directive may appear more than once at the same location.
deprecationReasonMaybe<string>Reason this element is deprecated, if one was provided.
extensionsReadonly<GraphQLDirectiveExtensions>Extension fields to include in the formatted result.
astNodeMaybe<DirectiveDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodesreadonly DirectiveExtensionNode[]AST extension nodes applied to this schema element.

toConfig()

Returns a normalized configuration object for this object.

Signature:

toConfig(): GraphQLDirectiveNormalizedConfig;

Returns
TypeDescription
GraphQLDirectiveNormalizedConfigA configuration object that can be used to recreate this object.

Example
import { DirectiveLocation } from 'graphql/language';
import { GraphQLDirective, GraphQLString } from 'graphql/type';
 
const tag = new GraphQLDirective({
  name: 'tag',
  locations: [DirectiveLocation.FIELD_DEFINITION],
  args: {
    name: { type: GraphQLString },
  },
});
 
const config = tag.toConfig();
const tagCopy = new GraphQLDirective(config);
 
config.args.name.type; // => GraphQLString
tagCopy.args[0].name; // => 'name'

toString()

Returns the schema coordinate identifying this directive.

Signature:

toString(): string;

Returns
TypeDescription
stringThe directive schema coordinate.

Example
import { DirectiveLocation } from 'graphql/language';
import { GraphQLDirective } from 'graphql/type';
 
const tag = new GraphQLDirective({
  name: 'tag',
  locations: [DirectiveLocation.FIELD_DEFINITION],
});
 
tag.toString(); // => '@tag'

toJSON()

Returns the JSON representation used when this object is serialized.

Signature:

toJSON(): string;

Returns
TypeDescription
stringThe JSON-serializable representation.

Example
import { DirectiveLocation } from 'graphql/language';
import { GraphQLDirective } from 'graphql/type';
 
const tag = new GraphQLDirective({
  name: 'tag',
  locations: [DirectiveLocation.FIELD_DEFINITION],
});
 
tag.toJSON(); // => '@tag'
JSON.stringify({ directive: tag }); // => '{"directive":"@tag"}'

Functions

isDirective()

Test if the given value is a GraphQL directive.

Signature:

isDirective(
  directive: unknown,
): directive is GraphQLDirective;

Arguments
NameTypeDescription
directiveunknownValue to inspect.

Returns
TypeDescription
directive is GraphQLDirectiveTrue when the value is a GraphQLDirective.

Example
import { DirectiveLocation } from 'graphql/language';
import { GraphQLDirective, GraphQLString, isDirective } from 'graphql/type';
 
const upper = new GraphQLDirective({
  name: 'upper',
  locations: [DirectiveLocation.FIELD_DEFINITION],
});
 
isDirective(upper); // => true
isDirective(GraphQLString); // => false

assertDirective()

Returns the value as a GraphQLDirective, or throws if it is not a directive.

Signature:

assertDirective(directive: unknown): GraphQLDirective;

Arguments
NameTypeDescription
directiveunknownValue to inspect.

Returns
TypeDescription
GraphQLDirectiveThe value typed as a GraphQLDirective.

Example
import { DirectiveLocation } from 'graphql/language';
import { assertDirective, GraphQLDirective, GraphQLString } from 'graphql/type';
 
const upper = new GraphQLDirective({
  name: 'upper',
  locations: [DirectiveLocation.FIELD_DEFINITION],
});
 
assertDirective(upper); // => upper
assertDirective(GraphQLString); // throws an error

isSpecifiedDirective()

Returns true when the directive is one of the directives specified by GraphQL.

Signature:

isSpecifiedDirective(directive: GraphQLDirective): boolean;

Arguments
NameTypeDescription
directiveGraphQLDirectiveDirective to inspect.

Returns
TypeDescription
booleanTrue when the directive is specified by GraphQL.

Example
import {
  GraphQLDirective,
  GraphQLIncludeDirective,
  isSpecifiedDirective,
} from 'graphql/type';
import { DirectiveLocation } from 'graphql/language';
 
const customDirective = new GraphQLDirective({
  name: 'auth',
  locations: [DirectiveLocation.FIELD_DEFINITION],
});
 
isSpecifiedDirective(GraphQLIncludeDirective); // => true
isSpecifiedDirective(customDirective); // => false

Constants

GraphQLIncludeDirective

Used to conditionally include fields or fragments.


Type
GraphQLDirective

GraphQLSkipDirective

Used to conditionally skip (exclude) fields or fragments.


Type
GraphQLDirective

GraphQLDeferDirective

Experimental directive used to conditionally defer fragments.

This directive is exported for schemas that explicitly opt in to incremental delivery. It is not included in specifiedDirectives.


Type
GraphQLDirective

GraphQLStreamDirective

Experimental directive used to conditionally stream list fields.

This directive is exported for schemas that explicitly opt in to incremental delivery. It is not included in specifiedDirectives.


Type
GraphQLDirective

DEFAULT_DEPRECATION_REASON

Constant string used for default reason for a deprecation.


Type
'No longer supported'

GraphQLDeprecatedDirective

Used to declare element of a GraphQL schema as deprecated.

The reason argument is non-null and defaults to DEFAULT_DEPRECATION_REASON.


Type
GraphQLDirective

GraphQLSpecifiedByDirective

Used to provide a URL for specifying the behavior of custom scalar definitions.


Type
GraphQLDirective

GraphQLOneOfDirective

Used to indicate an Input Object is a OneOf Input Object.


Type
GraphQLDirective

specifiedDirectives

Full list of stable directives specified by GraphQL.js.

Experimental @defer and @stream are exported separately and are not included in this list.


Type
ReadonlyArray<GraphQLDirective>

Types

GraphQLDirectiveExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLDirectiveConfig

Interface. Configuration used to construct a GraphQLDirective.


Members
NameTypeDescription
namestringThe GraphQL name for this schema element.
description?Maybe<string>Human-readable description for this schema element, if provided.
locationsreadonly DirectiveLocation[]Locations where this directive may be applied.
args?Maybe<ObjMap<GraphQLArgumentConfig>>Arguments accepted by this field or directive.
isRepeatable?Maybe<boolean>Whether this directive may appear more than once at the same location.
deprecationReason?Maybe<string>Reason this element is deprecated, if one was provided.
extensions?Maybe<Readonly<GraphQLDirectiveExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<DirectiveDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodes?Maybe<readonly DirectiveExtensionNode[]>AST extension nodes applied to this schema element.

Category: Introspection

Functions

isIntrospectionType()

Returns true when the type is one of the built-in introspection types.

Signature:

isIntrospectionType(type: GraphQLNamedType): boolean;

Arguments
NameTypeDescription
typeGraphQLNamedTypeThe GraphQL type to inspect.

Returns
TypeDescription
booleanTrue when the type is one of the built-in introspection types.

Example
import { GraphQLString, isIntrospectionType, __Type } from 'graphql/type';
 
isIntrospectionType(__Type); // => true
isIntrospectionType(GraphQLString); // => false

Constants

__Schema

The introspection type describing a GraphQL schema.


Type
GraphQLObjectType

__Directive

The introspection type describing a GraphQL directive.


Type
GraphQLObjectType

__DirectiveLocation

The introspection enum describing directive locations.


Type
GraphQLEnumType

__Type

The introspection type describing GraphQL types.


Type
GraphQLObjectType

__Field

The introspection type describing object and interface fields.


Type
GraphQLObjectType

__InputValue

The introspection type describing arguments and input fields.


Type
GraphQLObjectType

__EnumValue

The introspection type describing enum values.


Type
GraphQLObjectType

__TypeKind

The introspection enum describing GraphQL type kinds.


Type
GraphQLEnumType

SchemaMetaFieldDef

Note that these are GraphQLField and not GraphQLFieldConfig, so the format for args is different.


Type
GraphQLField<unknown, unknown>

TypeMetaFieldDef

The __type meta field definition used by introspection.


Type
GraphQLField<unknown, unknown>

TypeNameMetaFieldDef

The __typename meta field definition used by execution and introspection.


Type
GraphQLField<unknown, unknown>

introspectionTypes

All introspection types defined by the GraphQL specification.


Type
ReadonlyArray<GraphQLNamedType>

Enumerations

TypeKind

Enumeration. The introspection enum describing the different kinds of GraphQL types.

This is not a TypeScript enum. GraphQL.js exports TypeKind as both a runtime const object of literal values and a TypeScript type alias for those values.


Members
NameValue
SCALAR"SCALAR"
OBJECT"OBJECT"
INTERFACE"INTERFACE"
UNION"UNION"
ENUM"ENUM"
INPUT_OBJECT"INPUT_OBJECT"
LIST"LIST"
NON_NULL"NON_NULL"

Category: Scalars

Functions

isSpecifiedScalarType()

Returns true when the scalar type is one of the scalars specified by GraphQL.

Signature:

isSpecifiedScalarType(type: GraphQLNamedType): boolean;

Arguments
NameTypeDescription
typeGraphQLNamedTypeThe GraphQL type to inspect.

Returns
TypeDescription
booleanTrue when the scalar type is one of the scalars specified by GraphQL.

Example
import {
  GraphQLScalarType,
  GraphQLString,
  isSpecifiedScalarType,
} from 'graphql/type';
 
const DateTime = new GraphQLScalarType({
  name: 'DateTime',
});
 
isSpecifiedScalarType(GraphQLString); // => true
isSpecifiedScalarType(DateTime); // => false

Constants

GRAPHQL_MAX_INT

Maximum possible Int value as per GraphQL Spec (32-bit signed integer). n.b. This differs from JavaScript’s numbers that are IEEE 754 doubles safe up-to 2^53 - 1


Type
2147483647

GRAPHQL_MIN_INT

Minimum possible Int value as per GraphQL Spec (32-bit signed integer). n.b. This differs from JavaScript’s numbers that are IEEE 754 doubles safe starting at -(2^53 - 1)


Type
-2147483648

GraphQLInt

The built-in Int scalar type.


Type
GraphQLScalarType<number>

GraphQLFloat

The built-in Float scalar type.


Type
GraphQLScalarType<number>

GraphQLString

The built-in String scalar type.


Type
GraphQLScalarType<string>

GraphQLBoolean

The built-in Boolean scalar type.


Type
GraphQLScalarType<boolean>

GraphQLID

The built-in ID scalar type.


Type
GraphQLScalarType<string>

specifiedScalarTypes

All built-in scalar types defined by the GraphQL specification.


Type
ReadonlyArray<GraphQLScalarType>

Category: Schema

Classes

GraphQLSchema

Schema Definition

A Schema is created by supplying the root types of each type of operation, query and mutation (optional). A schema definition is then supplied to the validator and executor.


Example 1
const MyAppQueryRootType = new GraphQLObjectType({
  name: 'Query',
  fields: {
    greeting: { type: GraphQLString },
  },
});
 
const MyAppMutationRootType = new GraphQLObjectType({
  name: 'Mutation',
  fields: {
    setGreeting: { type: GraphQLString },
  },
});
 
const MyAppSchema = new GraphQLSchema({
  query: MyAppQueryRootType,
  mutation: MyAppMutationRootType,
});

Example 2

When the schema is constructed, by default only the types that are reachable by traversing the root types are included, other types must be explicitly referenced.

const characterInterface = new GraphQLInterfaceType({
  name: 'Character',
  fields: {
    name: { type: GraphQLString },
  },
});
 
const humanType = new GraphQLObjectType({
  name: 'Human',
  interfaces: [characterInterface],
  fields: {
    name: { type: GraphQLString },
  },
});
 
const droidType = new GraphQLObjectType({
  name: 'Droid',
  interfaces: [characterInterface],
  fields: {
    name: { type: GraphQLString },
  },
});
 
const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      hero: { type: characterInterface },
    },
  }),
  // Since this schema references only the `Character` interface it's
  // necessary to explicitly list the types that implement it if
  // you want them to be included in the final schema.
  types: [humanType, droidType],
});

Example 3

If an array of directives are provided to GraphQLSchema, that will be the exact list of directives represented and allowed. If directives is not provided then a default set of the specified directives (e.g. @include and @skip) will be used. If you wish to provide additional directives to these specified directives, you must explicitly declare them.

const MyAppSchema = new GraphQLSchema({
  query: MyAppQueryRootType,
  directives: specifiedDirectives.concat([myCustomDirective]),
});

Constructor

Creates a GraphQLSchema instance.

Signature:

new GraphQLSchema(config: Readonly<GraphQLSchemaConfig>);

Arguments
NameTypeDescription
configReadonly<GraphQLSchemaConfig>Configuration describing this object.

Members
NameTypeDescription
descriptionMaybe<string>Human-readable description for this schema element, if provided.
extensionsReadonly<GraphQLSchemaExtensions>Extension fields to include in the formatted result.
astNodeMaybe<SchemaDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodesreadonly SchemaExtensionNode[]AST extension nodes applied to this schema element.
assumeValidbooleanWhether this schema instance skips validation checks.

getQueryType()

Returns the root object type for query operations.

Signature:

getQueryType(): Maybe<GraphQLObjectType>;

Returns
TypeDescription
Maybe<GraphQLObjectType>The query root type, if this schema defines one.

Example
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type Query {
    greeting: String
  }
`);
 
schema.getQueryType()?.name; // => 'Query'

getMutationType()

Returns the root object type for mutation operations.

Signature:

getMutationType(): Maybe<GraphQLObjectType>;

Returns
TypeDescription
Maybe<GraphQLObjectType>The mutation root type, if this schema defines one.

Example
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type Query {
    greeting: String
  }
 
  type Mutation {
    setGreeting(value: String!): String
  }
`);
 
schema.getMutationType()?.name; // => 'Mutation'

getSubscriptionType()

Returns the root object type for subscription operations.

Signature:

getSubscriptionType(): Maybe<GraphQLObjectType>;

Returns
TypeDescription
Maybe<GraphQLObjectType>The subscription root type, if this schema defines one.

Example
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type Query {
    greeting: String
  }
 
  type Subscription {
    greetings: String
  }
`);
 
schema.getSubscriptionType()?.name; // => 'Subscription'

getRootType()

Returns the root object type for the requested operation kind.

Signature:

getRootType(
  operation: OperationTypeNode,
): Maybe<GraphQLObjectType>;

Arguments
NameTypeDescription
operationOperationTypeNodeOperation kind to resolve.

Returns
TypeDescription
Maybe<GraphQLObjectType>The root object type for the operation kind, if this schema defines one.

Example
import { OperationTypeNode } from 'graphql/language';
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type Query {
    greeting: String
  }
 
  type Mutation {
    setGreeting(value: String!): String
  }
`);
 
schema.getRootType(OperationTypeNode.QUERY)?.name; // => 'Query'
schema.getRootType(OperationTypeNode.MUTATION)?.name; // => 'Mutation'
schema.getRootType(OperationTypeNode.SUBSCRIPTION); // => undefined

getTypeMap()

Returns all named types known to this schema.

Signature:

getTypeMap(): ObjMap<GraphQLNamedType>;

Returns
TypeDescription
ObjMap<GraphQLNamedType>A map of schema types keyed by type name.

Example
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type User {
    name: String
  }
 
  type Query {
    viewer: User
  }
`);
 
const typeMap = schema.getTypeMap();
 
typeMap.User.name; // => 'User'
typeMap.Query.name; // => 'Query'
typeMap.String.name; // => 'String'

getType()

Returns the named type with the provided name.

Signature:

getType(
  name: string,
): GraphQLNamedType | undefined;

Arguments
NameTypeDescription
namestringThe GraphQL name to look up.

Returns
TypeDescription
GraphQLNamedType | undefinedThe named schema type, if one exists.

Example
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type User {
    name: String
  }
 
  type Query {
    viewer: User
  }
`);
 
schema.getType('User')?.toString(); // => 'User'
schema.getType('Missing'); // => undefined

getPossibleTypes()

Returns object types that may be returned for an abstract type.

Signature:

getPossibleTypes(
  abstractType: GraphQLAbstractType,
): readonly GraphQLObjectType[];

Arguments
NameTypeDescription
abstractTypeGraphQLAbstractTypeInterface or union type to inspect.

Returns
TypeDescription
readonly GraphQLObjectType[]Object types that may satisfy the abstract type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInterfaceType, assertUnionType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Organization implements Node {
    id: ID!
  }
 
  union SearchResult = User | Organization
 
  type Query {
    node: Node
    search: [SearchResult]
  }
`);
 
const Node = assertInterfaceType(schema.getType('Node'));
const SearchResult = assertUnionType(schema.getType('SearchResult'));
 
schema.getPossibleTypes(Node).map((type) => type.name); // => ['User', 'Organization']
schema.getPossibleTypes(SearchResult).map((type) => type.name); // => ['User', 'Organization']

getImplementations()

Returns objects and interfaces that implement an interface type.

Signature:

getImplementations(interfaceType: GraphQLInterfaceType): {
  objects: readonly GraphQLObjectType[];
  interfaces: readonly GraphQLInterfaceType[];
};

Arguments
NameTypeDescription
interfaceTypeGraphQLInterfaceTypeInterface type to inspect.

Returns
TypeDescription
{ objects: readonly GraphQLObjectType[]; interfaces: readonly GraphQLInterfaceType[]; }Object and interface implementations of the interface.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInterfaceType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Resource {
    url: String!
  }
 
  interface Image implements Resource {
    url: String!
    width: Int
  }
 
  type Photo implements Resource & Image {
    url: String!
    width: Int
  }
 
  type Query {
    resource: Resource
  }
`);
 
const Resource = assertInterfaceType(schema.getType('Resource'));
const implementations = schema.getImplementations(Resource);
 
implementations.interfaces.map((type) => type.name); // => ['Image']
implementations.objects.map((type) => type.name); // => ['Photo']

isSubType()

Returns whether one type is a possible runtime subtype of an abstract type.

Signature:

isSubType(
  abstractType: GraphQLAbstractType,
  maybeSubType: GraphQLObjectType | GraphQLInterfaceType,
): boolean;

Arguments
NameTypeDescription
abstractTypeGraphQLAbstractTypeInterface or union type to inspect.
maybeSubTypeGraphQLObjectType | GraphQLInterfaceTypeObject or interface type to test as a possible subtype.

Returns
TypeDescription
booleanTrue when the subtype may satisfy the abstract type.

Example
import { buildSchema } from 'graphql/utilities';
import { assertInterfaceType, assertObjectType } from 'graphql/type';
 
const schema = buildSchema(`
  interface Node {
    id: ID!
  }
 
  type User implements Node {
    id: ID!
  }
 
  type Review {
    body: String
  }
 
  type Query {
    node: Node
    review: Review
  }
`);
 
const Node = assertInterfaceType(schema.getType('Node'));
const User = assertObjectType(schema.getType('User'));
const Review = assertObjectType(schema.getType('Review'));
 
schema.isSubType(Node, User); // => true
schema.isSubType(Node, Review); // => false

getDirectives()

Returns directives available in this schema.

Signature:

getDirectives(): readonly GraphQLDirective[];

Returns
TypeDescription
readonly GraphQLDirective[]Directives available in this schema.

Example
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  directive @upper on FIELD_DEFINITION
 
  type Query {
    greeting: String @upper
  }
`);
 
schema.getDirectives().map((directive) => directive.name); // => ['include', 'skip', 'deprecated', 'specifiedBy', 'oneOf', 'upper']

getDirective()

Returns the current directive definition.

Signature:

getDirective(
  name: string,
): Maybe<GraphQLDirective>;

Arguments
NameTypeDescription
namestringThe GraphQL name to look up.

Returns
TypeDescription
Maybe<GraphQLDirective>The current directive definition, if known.

Example
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  directive @upper on FIELD_DEFINITION
 
  type Query {
    greeting: String @upper
  }
`);
 
schema.getDirective('upper')?.name; // => 'upper'
schema.getDirective('missing'); // => undefined

getField()

This method looks up the field on the given type definition. It has special casing for the three introspection fields, __schema, __type and __typename.

__typename is special because it can always be queried as a field, even in situations where no other fields are allowed, like on a Union.

__schema and __type could get automatically added to the query type, but that would require mutating type definitions, which would cause issues.

Signature:

getField(
  parentType: GraphQLCompositeType,
  fieldName: string,
): GraphQLField<unknown, unknown> | undefined;

Arguments
NameTypeDescription
parentTypeGraphQLCompositeTypeComposite type to look up the field on.
fieldNamestringField name to look up.

Returns
TypeDescription
GraphQLField<unknown, unknown> | undefinedThe field definition, including supported introspection fields.

Example
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type Query {
    greeting: String
  }
`);
const queryType = schema.getQueryType();
 
schema.getField(queryType, 'greeting')?.name; // => 'greeting'
schema.getField(queryType, '__typename')?.name; // => '__typename'
schema.getField(queryType, 'missing'); // => undefined

toConfig()

Returns a normalized configuration object for this object.

The returned config preserves the original assumeValid flag so the schema can be recreated with the same validation behavior.

Signature:

toConfig(): GraphQLSchemaNormalizedConfig;

Returns
TypeDescription
GraphQLSchemaNormalizedConfigA configuration object that can be used to recreate this object.

Example
import { buildSchema } from 'graphql/utilities';
import { GraphQLSchema } from 'graphql/type';
 
const schema = buildSchema(`
  type Query {
    greeting: String
  }
`);
 
const config = schema.toConfig();
const schemaCopy = new GraphQLSchema(config);
 
config.query?.name; // => 'Query'
schemaCopy.getQueryType()?.name; // => 'Query'

Functions

isSchema()

Test if the given value is a GraphQL schema.

Signature:

isSchema(
  schema: unknown,
): schema is GraphQLSchema;

Arguments
NameTypeDescription
schemaunknownValue to inspect.

Returns
TypeDescription
schema is GraphQLSchemaTrue when the value is a GraphQLSchema.

Example
import { buildSchema } from 'graphql/utilities';
import { GraphQLString, isSchema } from 'graphql/type';
 
const schema = buildSchema(`
  type Query {
    greeting: String
  }
`);
 
isSchema(schema); // => true
isSchema(GraphQLString); // => false

assertSchema()

Returns the value as a GraphQLSchema, or throws if it is not a schema.

Signature:

assertSchema(schema: unknown): GraphQLSchema;

Arguments
NameTypeDescription
schemaunknownGraphQL schema to use.

Returns
TypeDescription
GraphQLSchemaThe value typed as a GraphQLSchema.

Example
import { buildSchema } from 'graphql/utilities';
import { assertSchema, GraphQLString } from 'graphql/type';
 
const schema = buildSchema(`
  type Query {
    greeting: String
  }
`);
 
assertSchema(schema); // => schema
assertSchema(GraphQLString); // throws an error

Types

GraphQLSchemaExtensions

Interface. Custom extensions

Remarks: Use a unique identifier name for your extension, for example the name of your library or project. Do not use a shortened identifier as this increases the risk of conflicts. We recommend you add at most one extension field, an object which can contain all the values you need.


GraphQLSchemaConfig

Interface. Configuration used to construct a GraphQLSchema.


Members
NameTypeDescription
description?Maybe<string>Human-readable description for this schema element, if provided.
query?Maybe<GraphQLObjectType>Root object type for query operations.
mutation?Maybe<GraphQLObjectType>Root object type for mutation operations.
subscription?Maybe<GraphQLObjectType>Root object type for subscription operations.
types?Maybe<readonly GraphQLNamedType[]>Object types that belong to this union type.
directives?Maybe<readonly GraphQLDirective[]>Directives available in this schema or applied to this AST node.
extensions?Maybe<Readonly<GraphQLSchemaExtensions>>Extension fields to include in the formatted result.
astNode?Maybe<SchemaDefinitionNode>AST node from which this schema element was built, if available.
extensionASTNodes?Maybe<readonly SchemaExtensionNode[]>AST extension nodes applied to this schema element.

Category: Validation

Functions

validateSchema()

Implements the “Type Validation” sub-sections of the specification’s “Type System” section.

Validation runs synchronously, returning an array of encountered errors, or an empty array if no errors were encountered and the Schema is valid.

Signature:

validateSchema(
  schema: GraphQLSchema,
): readonly GraphQLError[];

Arguments
NameTypeDescription
schemaGraphQLSchemaGraphQL schema to use.

Returns
TypeDescription
readonly GraphQLError[]Schema validation errors, or an empty array when the schema is valid.

Example
import { validateSchema } from 'graphql/type';
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type Query {
    name: String
  }
`);
const errors = validateSchema(schema);
 
errors; // => []

assertValidSchema()

Utility function which asserts a schema is valid by throwing an error if it is invalid.

Signature:

assertValidSchema(schema: GraphQLSchema): void;

Arguments
NameTypeDescription
schemaGraphQLSchemaGraphQL schema to use.

Example
import { assertValidSchema } from 'graphql/type';
import { buildSchema } from 'graphql/utilities';
 
const schema = buildSchema(`
  type Query {
    name: String
  }
`);
 
assertValidSchema(schema); // does not throw