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

Parse, print, and visit GraphQL language source files and AST nodes.

These exports are also available from the root graphql package.

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

Category: AST

Classes:
LocationToken

Types:
ASTNodeASTKindToNodeNameNodeDocumentNodeDefinitionNodeExecutableDefinitionNodeOperationDefinitionNodeSubscriptionOperationDefinitionNodeVariableDefinitionNodeVariableNodeSelectionSetNodeSelectionNodeFieldNodeArgumentNodeConstArgumentNodeFragmentArgumentNodeFragmentSpreadNodeInlineFragmentNodeFragmentDefinitionNodeValueNodeConstValueNodeIntValueNodeFloatValueNodeStringValueNodeBooleanValueNodeNullValueNodeEnumValueNodeListValueNodeConstListValueNodeObjectValueNodeConstObjectValueNodeObjectFieldNodeConstObjectFieldNodeDirectiveNodeConstDirectiveNodeTypeNodeNamedTypeNodeListTypeNodeNonNullTypeNodeTypeSystemDefinitionNodeSchemaDefinitionNodeOperationTypeDefinitionNodeTypeDefinitionNodeScalarTypeDefinitionNodeObjectTypeDefinitionNodeFieldDefinitionNodeInputValueDefinitionNodeInterfaceTypeDefinitionNodeUnionTypeDefinitionNodeEnumTypeDefinitionNodeEnumValueDefinitionNodeInputObjectTypeDefinitionNodeDirectiveDefinitionNodeTypeSystemExtensionNodeSchemaExtensionNodeTypeExtensionNodeScalarTypeExtensionNodeObjectTypeExtensionNodeInterfaceTypeExtensionNodeUnionTypeExtensionNodeEnumTypeExtensionNodeInputObjectTypeExtensionNodeDirectiveExtensionNodeSchemaCoordinateNodeTypeCoordinateNodeMemberCoordinateNodeArgumentCoordinateNodeDirectiveCoordinateNodeDirectiveArgumentCoordinateNode

Classes

Location

Contains a range of UTF-8 character offsets and token references that identify the region of the source from which the AST derived.


Constructor

Creates a Location instance.

Signature:

new Location(
  startToken: Token,
  endToken: Token,
  source: Source,
);

Arguments
NameTypeDescription
startTokenTokenThe start token.
endTokenTokenThe end token.
sourceSourceSource document used to derive error locations.

Members
NameTypeDescription
startnumberThe character offset at which this Node begins.
endnumberThe character offset at which this Node ends.
startTokenTokenThe Token at which this Node begins.
endTokenTokenThe Token at which this Node ends.
sourceSourceThe Source document the AST represents.

toJSON()

Returns a JSON representation of this location.

Signature:

toJSON(): {
  start: number;
  end: number;
};

Returns
TypeDescription
{ start: number; end: number }The JSON-serializable representation.

Example
import { parse } from 'graphql/language';
 
const document = parse('{ hello }');
const location = document.loc?.toJSON();
 
location; // => { start: 0, end: 9 }

Token

Represents a range of characters represented by a lexical token within a Source.


Constructor

Creates a Token instance.

Signature:

new Token(
  kind: TokenKind,
  start: number,
  end: number,
  line: number,
  column: number,
  value?: string,
);

Arguments
NameTypeDescription
kindTokenKindToken kind produced by lexical analysis.
startnumberCharacter offset where this token begins.
endnumberCharacter offset where this token ends.
linenumberOne-indexed line number where this token begins.
columnnumberOne-indexed column number where this token begins.
value?stringInterpreted value for non-punctuation tokens.

Members
NameTypeDescription
kindTokenKindThe kind of Token.
startnumberThe character offset at which this Node begins.
endnumberThe character offset at which this Node ends.
linenumberThe 1-indexed line number on which this Token appears.
columnnumberThe 1-indexed column number at which this Token begins.
valuestringFor non-punctuation tokens, represents the interpreted value of the token.
Note: is undefined for punctuation tokens, but typed as string for
convenience in the parser.
prevToken | nullTokens exist as nodes in a double-linked-list amongst all tokens
including ignored tokens. <SOF> is always the first node and <EOF>
the last.
nextToken | nullNext token in the token stream, including ignored tokens.

toJSON()

Returns a JSON representation of this token.

Signature:

toJSON(): {
  kind: TokenKind;
  value?: string;
  line: number;
  column: number;
};

Returns
TypeDescription
{ kind: TokenKind; value?: string; line: number; column: number; }The JSON-serializable representation.

Example
import { Lexer, Source } from 'graphql/language';
 
const lexer = new Lexer(new Source('{ hello }'));
const token = lexer.advance().toJSON();
 
token; // => { kind: '{', value: undefined, line: 1, column: 1 }

Types

ASTNode

Type alias. The list of all possible AST node types.

type ASTNode =
  | NameNode
  | DocumentNode
  | OperationDefinitionNode
  | VariableDefinitionNode
  | VariableNode
  | SelectionSetNode
  | FieldNode
  | ArgumentNode
  | FragmentArgumentNode
  | FragmentSpreadNode
  | InlineFragmentNode
  | FragmentDefinitionNode
  | IntValueNode
  | FloatValueNode
  | StringValueNode
  | BooleanValueNode
  | NullValueNode
  | EnumValueNode
  | ListValueNode
  | ObjectValueNode
  | ObjectFieldNode
  | DirectiveNode
  | NamedTypeNode
  | ListTypeNode
  | NonNullTypeNode
  | SchemaDefinitionNode
  | OperationTypeDefinitionNode
  | ScalarTypeDefinitionNode
  | ObjectTypeDefinitionNode
  | FieldDefinitionNode
  | InputValueDefinitionNode
  | InterfaceTypeDefinitionNode
  | UnionTypeDefinitionNode
  | EnumTypeDefinitionNode
  | EnumValueDefinitionNode
  | InputObjectTypeDefinitionNode
  | DirectiveDefinitionNode
  | SchemaExtensionNode
  | ScalarTypeExtensionNode
  | ObjectTypeExtensionNode
  | InterfaceTypeExtensionNode
  | UnionTypeExtensionNode
  | EnumTypeExtensionNode
  | InputObjectTypeExtensionNode
  | DirectiveExtensionNode
  | TypeCoordinateNode
  | MemberCoordinateNode
  | ArgumentCoordinateNode
  | DirectiveCoordinateNode
  | DirectiveArgumentCoordinateNode;

ASTKindToNode

Type alias. Utility type listing all nodes indexed by their kind.

type ASTKindToNode = mapped object;

NameNode

Interface. An identifier in a GraphQL document.


Members
NameTypeDescription
kind'Name'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
valuestringParsed value represented by this node.

DocumentNode

Interface. The root AST node for a parsed GraphQL document.


Members
NameTypeDescription
kind'Document'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
definitionsreadonly DefinitionNode[]Top-level executable and type-system definitions in this document.
tokenCount?numberThe number of lexical tokens parsed for this document, if token counting was enabled.

DefinitionNode

Type alias. Any top-level definition that may appear in a GraphQL document.

type DefinitionNode =
  | ExecutableDefinitionNode
  | TypeSystemDefinitionNode
  | TypeSystemExtensionNode;

ExecutableDefinitionNode

Type alias. Any executable definition that may appear in an operation document.

type ExecutableDefinitionNode = OperationDefinitionNode | FragmentDefinitionNode;

OperationDefinitionNode

Interface. A query, mutation, or subscription operation definition.


Members
NameTypeDescription
kind'OperationDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
operationOperationTypeNodeThe operation selected for execution.
name?NameNodeName node identifying this AST node.
variableDefinitions?readonly VariableDefinitionNode[]Variable definitions declared by this operation or fragment.
directives?readonly DirectiveNode[]Directives available in this schema or applied to this AST node.
selectionSetSelectionSetNodeSelections made by this operation, field, or fragment.

SubscriptionOperationDefinitionNode

Interface. A narrowed OperationDefinitionNode for subscription operations. Subscription operations go through a distinct execution pipeline (source event stream + per-event execution), so narrowing the operation type allows functions in that pipeline to accept only valid input.

interface SubscriptionOperationDefinitionNode extends OperationDefinitionNode

Members
NameTypeDescription
operation'subscription'Subscription operation kind for this definition.

VariableDefinitionNode

Interface. A variable declaration in an operation or experimental fragment definition.


Members
NameTypeDescription
kind'VariableDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
variableVariableNodeThe variable being defined or referenced.
typeTypeNodeThe GraphQL type reference or runtime type for this element.
defaultValue?ConstValueNodeDefault value used when no explicit value is supplied.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.

VariableNode

Interface. A variable reference, such as $id.


Members
NameTypeDescription
kind'Variable'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.

SelectionSetNode

Interface. A set of fields and fragments selected from an object, interface, or union.


Members
NameTypeDescription
kind'SelectionSet'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
selectionsreadonly SelectionNode[]Fields and fragments contained in this selection set.

SelectionNode

Type alias. Any selection that may appear inside a selection set.

type SelectionNode =
  | FieldNode
  | FragmentSpreadNode
  | InlineFragmentNode;

FieldNode

Interface. A field selected in an executable GraphQL document.


Members
NameTypeDescription
kind'Field'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
alias?NameNodeThe response-key alias for this field, if one was supplied.
nameNameNodeName node identifying this AST node.
arguments?readonly ArgumentNode[]Arguments supplied to this field, directive, or coordinate.
directives?readonly DirectiveNode[]Directives available in this schema or applied to this AST node.
selectionSet?SelectionSetNodeSelections made by this operation, field, or fragment.

ArgumentNode

Interface. An argument supplied to a field or directive.


Members
NameTypeDescription
kind'Argument'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
valueValueNodeParsed value represented by this node.

ConstArgumentNode

Interface. An argument node whose value is guaranteed to be constant.


Members
NameTypeDescription
kind'Argument'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
valueConstValueNodeParsed value represented by this node.

FragmentArgumentNode

Interface. Variable definition declared by a fragment argument.


Members
NameTypeDescription
kind'FragmentArgument'AST node kind for a fragment argument.
loc?LocationSource location for this fragment argument.
nameNameNodeVariable name declared by this fragment argument.
valueValueNodeDefault value literal for this fragment argument, if provided.

FragmentSpreadNode

Interface. A named fragment spread, such as ...userFields.


Members
NameTypeDescription
kind'FragmentSpread'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
arguments?readonly FragmentArgumentNode[]Argument values supplied to the referenced fragment.
directives?readonly DirectiveNode[]Directives available in this schema or applied to this AST node.

InlineFragmentNode

Interface. An inline fragment spread with an optional type condition.


Members
NameTypeDescription
kind'InlineFragment'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
typeCondition?NamedTypeNodeThe type condition that limits where this fragment applies.
directives?readonly DirectiveNode[]Directives available in this schema or applied to this AST node.
selectionSetSelectionSetNodeSelections made by this operation, field, or fragment.

FragmentDefinitionNode

Interface. A reusable fragment definition declared in an executable document.


Members
NameTypeDescription
kind'FragmentDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
variableDefinitions?readonly VariableDefinitionNode[]Experimental variable definitions declared by this fragment definition.
typeConditionNamedTypeNodeThe type condition that limits where this fragment applies.
directives?readonly DirectiveNode[]Directives available in this schema or applied to this AST node.
selectionSetSelectionSetNodeSelections made by this operation, field, or fragment.

ValueNode

Type alias. Any value literal that may appear in an executable GraphQL document.

type ValueNode =
  | VariableNode
  | IntValueNode
  | FloatValueNode
  | StringValueNode
  | BooleanValueNode
  | NullValueNode
  | EnumValueNode
  | ListValueNode
  | ObjectValueNode;

ConstValueNode

Type alias. Any value literal that is guaranteed not to contain a variable reference.

type ConstValueNode =
  | IntValueNode
  | FloatValueNode
  | StringValueNode
  | BooleanValueNode
  | NullValueNode
  | EnumValueNode
  | ConstListValueNode
  | ConstObjectValueNode;

IntValueNode

Interface. An integer value literal.


Members
NameTypeDescription
kind'IntValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
valuestringParsed value represented by this node.

FloatValueNode

Interface. A floating-point value literal.


Members
NameTypeDescription
kind'FloatValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
valuestringParsed value represented by this node.

StringValueNode

Interface. A string value literal.


Members
NameTypeDescription
kind'StringValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
valuestringParsed value represented by this node.
block?booleanWhether this string was parsed from block string syntax.

BooleanValueNode

Interface. A boolean value literal.


Members
NameTypeDescription
kind'BooleanValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
valuebooleanParsed value represented by this node.

NullValueNode

Interface. A null value literal.


Members
NameTypeDescription
kind'NullValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.

EnumValueNode

Interface. An enum value literal.


Members
NameTypeDescription
kind'EnumValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
valuestringParsed value represented by this node.

ListValueNode

Interface. A list value literal.


Members
NameTypeDescription
kind'ListValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
valuesreadonly ValueNode[]Values contained in this enum, list, or input-object definition.

ConstListValueNode

Interface. A list value literal whose elements are all constant values.


Members
NameTypeDescription
kind'ListValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
valuesreadonly ConstValueNode[]Values contained in this enum, list, or input-object definition.

ObjectValueNode

Interface. An input object value literal.


Members
NameTypeDescription
kind'ObjectValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
fieldsreadonly ObjectFieldNode[]Fields declared by this object, interface, input object, or literal.

ConstObjectValueNode

Interface. An input object value literal whose fields are all constant values.


Members
NameTypeDescription
kind'ObjectValue'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
fieldsreadonly ConstObjectFieldNode[]Fields declared by this object, interface, input object, or literal.

ObjectFieldNode

Interface. A field inside an input object value literal.


Members
NameTypeDescription
kind'ObjectField'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
valueValueNodeParsed value represented by this node.

ConstObjectFieldNode

Interface. A field inside a constant input object value literal.


Members
NameTypeDescription
kind'ObjectField'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
valueConstValueNodeParsed value represented by this node.

DirectiveNode

Interface. A directive applied to an executable or type-system location.


Members
NameTypeDescription
kind'Directive'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
arguments?readonly ArgumentNode[]Arguments supplied to this field, directive, or coordinate.

ConstDirectiveNode

Interface. A directive whose arguments are all constant values.


Members
NameTypeDescription
kind'Directive'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
arguments?readonly ConstArgumentNode[]Arguments supplied to this field, directive, or coordinate.

TypeNode

Type alias. Any GraphQL type reference AST node.

type TypeNode =
  | NamedTypeNode
  | ListTypeNode
  | NonNullTypeNode;

NamedTypeNode

Interface. A named type reference.


Members
NameTypeDescription
kind'NamedType'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.

ListTypeNode

Interface. A list type reference.


Members
NameTypeDescription
kind'ListType'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
typeTypeNodeThe GraphQL type reference or runtime type for this element.

NonNullTypeNode

Interface. A non-null type reference.


Members
NameTypeDescription
kind'NonNullType'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
typeNamedTypeNode | ListTypeNodeThe GraphQL type reference or runtime type for this element.

TypeSystemDefinitionNode

Type alias. Any type-system definition that may appear in a schema document.

type TypeSystemDefinitionNode =
  | SchemaDefinitionNode
  | TypeDefinitionNode
  | DirectiveDefinitionNode;

SchemaDefinitionNode

Interface. A schema definition in a type-system document.


Members
NameTypeDescription
kind'SchemaDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
operationTypesreadonly OperationTypeDefinitionNode[]Root operation types declared by this schema definition or extension.

OperationTypeDefinitionNode

Interface. A root operation type declaration inside a schema definition or extension.


Members
NameTypeDescription
kind'OperationTypeDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
operationOperationTypeNodeThe operation selected for execution.
typeNamedTypeNodeThe GraphQL type reference or runtime type for this element.

TypeDefinitionNode

Type alias. Any named type definition that may appear in a schema document.

type TypeDefinitionNode =
  | ScalarTypeDefinitionNode
  | ObjectTypeDefinitionNode
  | InterfaceTypeDefinitionNode
  | UnionTypeDefinitionNode
  | EnumTypeDefinitionNode
  | InputObjectTypeDefinitionNode;

ScalarTypeDefinitionNode

Interface. A scalar type definition in a type-system document.


Members
NameTypeDescription
kind'ScalarTypeDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.

ObjectTypeDefinitionNode

Interface. An object type definition in a type-system document.


Members
NameTypeDescription
kind'ObjectTypeDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
interfaces?readonly NamedTypeNode[]Interfaces implemented by this object or interface type.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
fields?readonly FieldDefinitionNode[]Fields declared by this object, interface, input object, or literal.

FieldDefinitionNode

Interface. A field definition declared by an object or interface type.


Members
NameTypeDescription
kind'FieldDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
arguments?readonly InputValueDefinitionNode[]Arguments supplied to this field, directive, or coordinate.
typeTypeNodeThe GraphQL type reference or runtime type for this element.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.

InputValueDefinitionNode

Interface. An argument or input-field definition.


Members
NameTypeDescription
kind'InputValueDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
typeTypeNodeThe GraphQL type reference or runtime type for this element.
defaultValue?ConstValueNodeDefault value used when no explicit value is supplied.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.

InterfaceTypeDefinitionNode

Interface. An interface type definition in a type-system document.


Members
NameTypeDescription
kind'InterfaceTypeDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
interfaces?readonly NamedTypeNode[]Interfaces implemented by this object or interface type.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
fields?readonly FieldDefinitionNode[]Fields declared by this object, interface, input object, or literal.

UnionTypeDefinitionNode

Interface. A union type definition in a type-system document.


Members
NameTypeDescription
kind'UnionTypeDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
types?readonly NamedTypeNode[]Object types that belong to this union type.

EnumTypeDefinitionNode

Interface. An enum type definition in a type-system document.


Members
NameTypeDescription
kind'EnumTypeDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
values?readonly EnumValueDefinitionNode[]Values contained in this enum, list, or input-object definition.

EnumValueDefinitionNode

Interface. An enum value definition.


Members
NameTypeDescription
kind'EnumValueDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.

InputObjectTypeDefinitionNode

Interface. An input object type definition in a type-system document.


Members
NameTypeDescription
kind'InputObjectTypeDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
fields?readonly InputValueDefinitionNode[]Fields declared by this object, interface, input object, or literal.

DirectiveDefinitionNode

Interface. A directive definition in a type-system document.


Members
NameTypeDescription
kind'DirectiveDefinition'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
description?StringValueNodeThe optional GraphQL description associated with this definition.
nameNameNodeName node identifying this AST node.
arguments?readonly InputValueDefinitionNode[]Arguments supplied to this field, directive, or coordinate.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
repeatablebooleanWhether this directive may appear more than once at the same location.
locationsreadonly NameNode[]Locations where this directive may be applied.

TypeSystemExtensionNode

Type alias. Any type-system extension that may appear in a schema extension document.

type TypeSystemExtensionNode =
  | SchemaExtensionNode
  | TypeExtensionNode
  | DirectiveExtensionNode;

SchemaExtensionNode

Interface. A schema extension in a type-system document.


Members
NameTypeDescription
kind'SchemaExtension'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
operationTypes?readonly OperationTypeDefinitionNode[]Root operation types declared by this schema definition or extension.

TypeExtensionNode

Type alias. Any named type extension that may appear in a schema extension document.

type TypeExtensionNode =
  | ScalarTypeExtensionNode
  | ObjectTypeExtensionNode
  | InterfaceTypeExtensionNode
  | UnionTypeExtensionNode
  | EnumTypeExtensionNode
  | InputObjectTypeExtensionNode;

ScalarTypeExtensionNode

Interface. A scalar type extension.


Members
NameTypeDescription
kind'ScalarTypeExtension'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.

ObjectTypeExtensionNode

Interface. An object type extension.


Members
NameTypeDescription
kind'ObjectTypeExtension'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
interfaces?readonly NamedTypeNode[]Interfaces implemented by this object or interface type.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
fields?readonly FieldDefinitionNode[]Fields declared by this object, interface, input object, or literal.

InterfaceTypeExtensionNode

Interface. An interface type extension.


Members
NameTypeDescription
kind'InterfaceTypeExtension'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
interfaces?readonly NamedTypeNode[]Interfaces implemented by this object or interface type.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
fields?readonly FieldDefinitionNode[]Fields declared by this object, interface, input object, or literal.

UnionTypeExtensionNode

Interface. A union type extension.


Members
NameTypeDescription
kind'UnionTypeExtension'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
types?readonly NamedTypeNode[]Object types that belong to this union type.

EnumTypeExtensionNode

Interface. An enum type extension.


Members
NameTypeDescription
kind'EnumTypeExtension'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
values?readonly EnumValueDefinitionNode[]Values contained in this enum, list, or input-object definition.

InputObjectTypeExtensionNode

Interface. An input object type extension.


Members
NameTypeDescription
kind'InputObjectTypeExtension'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.
fields?readonly InputValueDefinitionNode[]Fields declared by this object, interface, input object, or literal.

DirectiveExtensionNode

Interface. A directive extension.


Members
NameTypeDescription
kind'DirectiveExtension'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
directives?readonly ConstDirectiveNode[]Directives available in this schema or applied to this AST node.

SchemaCoordinateNode

Type alias. Any AST node representing a GraphQL schema coordinate.

type SchemaCoordinateNode =
  | TypeCoordinateNode
  | MemberCoordinateNode
  | ArgumentCoordinateNode
  | DirectiveCoordinateNode
  | DirectiveArgumentCoordinateNode;

TypeCoordinateNode

Interface. A schema coordinate that refers to a named type.


Members
NameTypeDescription
kind'TypeCoordinate'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.

MemberCoordinateNode

Interface. A schema coordinate that refers to a member of a named type.


Members
NameTypeDescription
kind'MemberCoordinate'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
memberNameNameNodeThe member name referenced by this schema coordinate.

ArgumentCoordinateNode

Interface. A schema coordinate that refers to a field or directive argument.


Members
NameTypeDescription
kind'ArgumentCoordinate'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
fieldNameNameNodeThe field name referenced by this schema coordinate.
argumentNameNameNodeThe argument name referenced by this schema coordinate.

DirectiveCoordinateNode

Interface. A schema coordinate that refers to a directive.


Members
NameTypeDescription
kind'DirectiveCoordinate'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.

DirectiveArgumentCoordinateNode

Interface. A schema coordinate that refers to a directive argument.


Members
NameTypeDescription
kind'DirectiveArgumentCoordinate'The discriminator identifying the concrete AST or introspection kind.
loc?LocationThe source location for this AST node, if location tracking was enabled.
nameNameNodeName node identifying this AST node.
argumentNameNameNodeThe argument name referenced by this schema coordinate.

Category: Kinds

Enumerations

OperationTypeNode

Enumeration. The operation types supported by GraphQL executable definitions.

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


Members
NameValue
QUERY"query"
MUTATION"mutation"
SUBSCRIPTION"subscription"

DirectiveLocation

Enumeration. The set of allowed directive location values.

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


Members
NameValueDescription
QUERY"QUERY"Directive location for query operations.
MUTATION"MUTATION"Directive location for mutation operations.
SUBSCRIPTION"SUBSCRIPTION"Directive location for subscription operations.
FIELD"FIELD"Directive location for field selections.
FRAGMENT_DEFINITION"FRAGMENT_DEFINITION"Directive location for fragment definitions.
FRAGMENT_SPREAD"FRAGMENT_SPREAD"Directive location for fragment spreads.
INLINE_FRAGMENT"INLINE_FRAGMENT"Directive location for inline fragments.
VARIABLE_DEFINITION"VARIABLE_DEFINITION"Directive location for variable definitions.
FRAGMENT_VARIABLE_DEFINITION"FRAGMENT_VARIABLE_DEFINITION"Directive location for fragment variable definitions.
SCHEMA"SCHEMA"Directive location for schema definitions and extensions.
SCALAR"SCALAR"Directive location for scalar type definitions and extensions.
OBJECT"OBJECT"Directive location for object type definitions and extensions.
FIELD_DEFINITION"FIELD_DEFINITION"Directive location for field definitions.
ARGUMENT_DEFINITION"ARGUMENT_DEFINITION"Directive location for argument definitions.
INTERFACE"INTERFACE"Directive location for interface type definitions and extensions.
UNION"UNION"Directive location for union type definitions and extensions.
ENUM"ENUM"Directive location for enum type definitions and extensions.
ENUM_VALUE"ENUM_VALUE"Directive location for enum value definitions.
INPUT_OBJECT"INPUT_OBJECT"Directive location for input object type definitions and extensions.
INPUT_FIELD_DEFINITION"INPUT_FIELD_DEFINITION"Directive location for input object field definitions.
DIRECTIVE_DEFINITION"DIRECTIVE_DEFINITION"Directive location for directive definitions and extensions.

Kind

Enumeration.

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


Members
NameValueDescription
NAME"Name"AST kind for name nodes.
DOCUMENT"Document"AST kind for document nodes.
OPERATION_DEFINITION"OperationDefinition"AST kind for operation definition nodes.
VARIABLE_DEFINITION"VariableDefinition"AST kind for variable definition nodes.
SELECTION_SET"SelectionSet"AST kind for selection set nodes.
FIELD"Field"AST kind for field selection nodes.
ARGUMENT"Argument"AST kind for argument nodes.
FRAGMENT_ARGUMENT"FragmentArgument"AST kind for fragment argument nodes.
FRAGMENT_SPREAD"FragmentSpread"AST kind for fragment spread nodes.
INLINE_FRAGMENT"InlineFragment"AST kind for inline fragment nodes.
FRAGMENT_DEFINITION"FragmentDefinition"AST kind for fragment definition nodes.
VARIABLE"Variable"AST kind for variable reference nodes.
INT"IntValue"AST kind for integer value nodes.
FLOAT"FloatValue"AST kind for floating-point value nodes.
STRING"StringValue"AST kind for string value nodes.
BOOLEAN"BooleanValue"AST kind for boolean value nodes.
NULL"NullValue"AST kind for null value nodes.
ENUM"EnumValue"AST kind for enum value nodes.
LIST"ListValue"AST kind for list value nodes.
OBJECT"ObjectValue"AST kind for object value nodes.
OBJECT_FIELD"ObjectField"AST kind for object field nodes.
DIRECTIVE"Directive"AST kind for directive nodes.
NAMED_TYPE"NamedType"AST kind for named type reference nodes.
LIST_TYPE"ListType"AST kind for list type reference nodes.
NON_NULL_TYPE"NonNullType"AST kind for non-null type reference nodes.
SCHEMA_DEFINITION"SchemaDefinition"AST kind for schema definition nodes.
OPERATION_TYPE_DEFINITION"OperationTypeDefinition"AST kind for operation type definition nodes.
SCALAR_TYPE_DEFINITION"ScalarTypeDefinition"AST kind for scalar type definition nodes.
OBJECT_TYPE_DEFINITION"ObjectTypeDefinition"AST kind for object type definition nodes.
FIELD_DEFINITION"FieldDefinition"AST kind for field definition nodes.
INPUT_VALUE_DEFINITION"InputValueDefinition"AST kind for input value definition nodes.
INTERFACE_TYPE_DEFINITION"InterfaceTypeDefinition"AST kind for interface type definition nodes.
UNION_TYPE_DEFINITION"UnionTypeDefinition"AST kind for union type definition nodes.
ENUM_TYPE_DEFINITION"EnumTypeDefinition"AST kind for enum type definition nodes.
ENUM_VALUE_DEFINITION"EnumValueDefinition"AST kind for enum value definition nodes.
INPUT_OBJECT_TYPE_DEFINITION"InputObjectTypeDefinition"AST kind for input object type definition nodes.
DIRECTIVE_DEFINITION"DirectiveDefinition"AST kind for directive definition nodes.
SCHEMA_EXTENSION"SchemaExtension"AST kind for schema extension nodes.
DIRECTIVE_EXTENSION"DirectiveExtension"AST kind for directive extension nodes.
SCALAR_TYPE_EXTENSION"ScalarTypeExtension"AST kind for scalar type extension nodes.
OBJECT_TYPE_EXTENSION"ObjectTypeExtension"AST kind for object type extension nodes.
INTERFACE_TYPE_EXTENSION"InterfaceTypeExtension"AST kind for interface type extension nodes.
UNION_TYPE_EXTENSION"UnionTypeExtension"AST kind for union type extension nodes.
ENUM_TYPE_EXTENSION"EnumTypeExtension"AST kind for enum type extension nodes.
INPUT_OBJECT_TYPE_EXTENSION"InputObjectTypeExtension"AST kind for input object type extension nodes.
TYPE_COORDINATE"TypeCoordinate"AST kind for type coordinate nodes.
MEMBER_COORDINATE"MemberCoordinate"AST kind for member coordinate nodes.
ARGUMENT_COORDINATE"ArgumentCoordinate"AST kind for argument coordinate nodes.
DIRECTIVE_COORDINATE"DirectiveCoordinate"AST kind for directive coordinate nodes.
DIRECTIVE_ARGUMENT_COORDINATE"DirectiveArgumentCoordinate"AST kind for directive argument coordinate nodes.

Category: Lexing

Classes:
Lexer

Enumerations:
TokenKind

Classes

Lexer

Given a Source object, creates a Lexer for that source. A Lexer is a stateful stream generator in that every time it is advanced, it returns the next token in the Source. Assuming the source lexes, the final Token emitted by the lexer will be of kind EOF, after which the lexer will repeatedly return the same EOF token whenever called.


Constructor

Creates a Lexer instance.

Signature:

new Lexer(source: Source);

Arguments
NameTypeDescription
sourceSourceSource document used to derive error locations.

Members
NameTypeDescription
sourceSourceSource document used to derive error locations.
lastTokenTokenMost recent non-ignored token returned by the lexer.
tokenTokenCurrent non-ignored token at the lexer cursor.
linenumberThe (1-indexed) line containing the current token.
lineStartnumberCharacter offset where the current line starts.

advance()

Advances the token stream to the next non-ignored token.

Signature:

advance(): Token;

Returns
TypeDescription
TokenThe next non-ignored token.

Example
import { Lexer, Source } from 'graphql/language';
 
const lexer = new Lexer(new Source('{ hello }'));
const token = lexer.advance();
 
token.kind; // => '{'
lexer.token; // => token

lookahead()

Looks ahead and returns the next non-ignored token, but does not change the state of Lexer.

Signature:

lookahead(): Token;

Returns
TypeDescription
TokenThe next non-ignored token without advancing the lexer.

Example
import { Lexer, Source } from 'graphql/language';
 
const lexer = new Lexer(new Source('{ hello }'));
const token = lexer.lookahead();
 
token.kind; // => '{'
lexer.token.kind; // => '<SOF>'

Enumerations

TokenKind

Enumeration. An exported enum describing the different kinds of tokens that the lexer emits.

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


Members
NameValue
SOF"<SOF>"
EOF"<EOF>"
BANG"!"
DOLLAR"$"
AMP"&"
PAREN_L"("
PAREN_R")"
DOT"."
SPREAD"..."
COLON":"
EQUALS"="
AT"@"
BRACKET_L"["
BRACKET_R"]"
BRACE_L"{"
PIPE"|"
BRACE_R"}"
NAME"Name"
INT"Int"
FLOAT"Float"
STRING"String"
BLOCK_STRING"BlockString"
COMMENT"Comment"

Category: Source

Classes

Source

A representation of source input to GraphQL. The name and locationOffset parameters are optional, but they are useful for clients who store GraphQL documents in source files. For example, if the GraphQL input starts at line 40 in a file named Foo.graphql, it might be useful for name to be "Foo.graphql" and location to be { line: 40, column: 1 }. The line and column properties in locationOffset are 1-indexed.


Constructor

Creates a Source instance.

Signature:

new Source(
  body: string,
  name: string = 'GraphQL request',
  locationOffset: {
    line: number;
    column: number;
  } = { line: 1, column: 1 },
);

Arguments
NameTypeDefaultDescription
bodystringThe GraphQL source text.
namestring'GraphQL request'Name used in diagnostics for this source.
locationOffset{ line: number; column: number }{ line: 1, column: 1 }One-indexed line and column where this source begins.

Members
NameTypeDescription
bodystringThe GraphQL source text.
namestringName used in diagnostics for this source, such as a file path or request name.
locationOffset{ line: number; column: number }One-indexed line and column where this source begins.

Functions

getLocation()

Takes a Source and a UTF-8 character offset, and returns the corresponding line and column as a SourceLocation.

Signature:

getLocation(
  source: Source,
  position: number,
): SourceLocation;

Arguments
NameTypeDescription
sourceSourceThe source document that contains the position.
positionnumberThe UTF-8 character offset in the source body.

Returns
TypeDescription
SourceLocationThe 1-indexed line and column for the given source position.

Example
import { Source, getLocation } from 'graphql/language';
 
const source = new Source('type Query { hello: String }');
const location = getLocation(source, 13);
 
location; // => { line: 1, column: 14 }

printLocation()

Render a helpful description of the location in the GraphQL Source document.

Signature:

printLocation(location: Location): string;

Arguments
NameTypeDescription
locationLocationThe AST location to print.

Returns
TypeDescription
stringA formatted source excerpt with line and column information.

Example
import { parse, printLocation } from 'graphql/language';
 
const document = parse('type Query { hello: String }');
const location = document.definitions[0].loc;
 
if (location) {
  const printed = printLocation(location);
 
  printed; // => 'GraphQL request:1:1\n1 | type Query { hello: String }\n  | ^'
}

printSourceLocation()

Render a helpful description of the location in the GraphQL Source document.

Signature:

printSourceLocation(
  source: Source,
  sourceLocation: SourceLocation,
): string;

Arguments
NameTypeDescription
sourceSourceThe source document that contains the location.
sourceLocationSourceLocationThe 1-indexed line and column to print.

Returns
TypeDescription
stringA formatted source excerpt with line and column information.

Example
import { Source, printSourceLocation } from 'graphql/language';
 
const source = new Source('type Query { hello: String }');
const printed = printSourceLocation(source, { line: 1, column: 14 });
 
printed; // => 'GraphQL request:1:14\n1 | type Query { hello: String }\n  |              ^'

Types

SourceLocation

Interface. Represents a location in a Source.


Members
NameTypeDescription
linenumberOne-indexed line number in the source document.
columnnumberOne-indexed column number in the source document.

Category: Parsing

Functions

parse()

Given a GraphQL source, parses it into a Document. Throws GraphQLError if a syntax error is encountered.

Signature:

parse(
  source: string | Source,
  options?: ParseOptions,
): DocumentNode;

Arguments
NameTypeDescription
sourcestring | SourceA GraphQL source string or source object.
options?ParseOptionsOptional parser configuration.

Returns
TypeDescription
DocumentNodeThe parsed GraphQL document AST.

Example 1
// Parse a GraphQL document with the default parser options.
import { parse } from 'graphql/language';
 
const document = parse('{ hero { name } }');
 
document.kind; // => 'Document'

Example 2
// This variant enables parser options and provides an explicit lexer.
import { Lexer, Source, parse } from 'graphql/language';
 
const document = parse(`
  {
    t { ...A(var: true) }
  }
  fragment A($var: Boolean = false) on T {
    name
  }
`, {
  experimentalFragmentArguments: true,
  maxTokens: 80,
  noLocation: true,
});
const directiveDocument = parse('directive @foo @bar on FIELD', {
  experimentalDirectivesOnDirectiveDefinitions: true,
});
const source = new Source('{ hero }');
const lexerDocument = parse(source, { lexer: new Lexer(source) });
 
document.definitions[0].kind; // => 'OperationDefinition'
document.definitions[1].kind; // => 'FragmentDefinition'
document.loc; // => undefined
directiveDocument.definitions[0].kind; // => 'DirectiveDefinition'
lexerDocument.definitions[0].kind; // => 'OperationDefinition'

parseValue()

Given a string containing a GraphQL value (ex. [42]), parse the AST for that value. Throws GraphQLError if a syntax error is encountered.

This is useful within tools that operate upon GraphQL Values directly and in isolation of complete GraphQL documents.

Consider providing the results to the utility function: valueFromAST().

Signature:

parseValue(
  source: string | Source,
  options?: ParseOptions,
): ValueNode;

Arguments
NameTypeDescription
sourcestring | SourceA GraphQL source string or source object containing a value.
options?ParseOptionsOptional parser configuration.

Returns
TypeDescription
ValueNodeThe parsed GraphQL value AST.

Example
import { parseValue } from 'graphql/language';
 
const value = parseValue('[42]');
 
value.kind; // => 'ListValue'

parseConstValue()

Similar to parseValue(), but raises a parse error if it encounters a variable. The return type will be a constant value.

Signature:

parseConstValue(
  source: string | Source,
  options?: ParseOptions,
): ConstValueNode;

Arguments
NameTypeDescription
sourcestring | SourceA GraphQL source string or source object containing a constant value.
options?ParseOptionsOptional parser configuration.

Returns
TypeDescription
ConstValueNodeThe parsed GraphQL constant value AST.

Example
import { parseConstValue } from 'graphql/language';
 
const value = parseConstValue('{ enabled: true }');
 
value.kind; // => 'ObjectValue'
parseConstValue('$variable'); // throws an error

parseType()

Given a string containing a GraphQL Type (ex. [Int!]), parse the AST for that type. Throws GraphQLError if a syntax error is encountered.

This is useful within tools that operate upon GraphQL Types directly and in isolation of complete GraphQL documents.

Consider providing the results to the utility function: typeFromAST().

Signature:

parseType(
  source: string | Source,
  options?: ParseOptions,
): TypeNode;

Arguments
NameTypeDescription
sourcestring | SourceA GraphQL source string or source object containing a type reference.
options?ParseOptionsOptional parser configuration.

Returns
TypeDescription
TypeNodeThe parsed GraphQL type AST.

Example
import { parseType } from 'graphql/language';
 
const type = parseType('[String!]');
 
type.kind; // => 'ListType'

parseSchemaCoordinate()

Given a string containing a GraphQL Schema Coordinate (ex. Type.field), parse the AST for that schema coordinate. Throws GraphQLError if a syntax error is encountered.

Consider providing the results to the utility function: resolveASTSchemaCoordinate(). Or calling resolveSchemaCoordinate() directly with an unparsed source.

Signature:

parseSchemaCoordinate(
  source: string | Source,
): SchemaCoordinateNode;

Arguments
NameTypeDescription
sourcestring | SourceA GraphQL source string or source object containing a schema coordinate.

Returns
TypeDescription
SchemaCoordinateNodeThe parsed GraphQL schema coordinate AST.

Example
import { parseSchemaCoordinate } from 'graphql/language';
 
const coordinate = parseSchemaCoordinate('Query.hero');
 
coordinate.kind; // => 'MemberCoordinate'

Types

ParseOptions

Interface. Configuration options to control parser behavior


Members
NameTypeDescription
noLocation?booleanBy default, the parser creates AST nodes that know the location
in the source that they correspond to. This configuration flag
disables that behavior for performance or testing.
maxTokens?numberParser CPU and memory usage is linear to the number of tokens in a document
however in extreme cases it becomes quadratic due to memory exhaustion.
Parsing happens before validation so even invalid queries can burn lots of
CPU time and memory.
To prevent this you can set a maximum number of tokens allowed within a document.
experimentalFragmentArguments?booleanEXPERIMENTAL:
If enabled, the parser will understand and parse fragment variable definitions
and arguments on fragment spreads. Fragment variable definitions will be represented
in the variableDefinitions field of the FragmentDefinitionNode.
Fragment spread arguments will be represented in the arguments field of FragmentSpreadNode.
experimentalDirectivesOnDirectiveDefinitions?booleanEXPERIMENTAL:
If enabled, the parser will parse directives on directive definitions.
This syntax is not part of the GraphQL specification and may change.

experimentalFragmentArguments Example
{
  t { ...A(var: true) }
}
fragment A($var: Boolean = false) on T {
  ...B(x: $var)
}

experimentalDirectivesOnDirectiveDefinitions Example
directive @foo @bar on FIELD

Category: AST Predicates

Functions

isDefinitionNode()

Returns true when the AST node is a definition node.

Signature:

isDefinitionNode(
  node: ASTNode,
): node is DefinitionNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is DefinitionNodeTrue when the AST node is a definition node.

Example
import { parse, isDefinitionNode } from 'graphql/language';
 
const document = parse('{ hello }');
 
isDefinitionNode(document.definitions[0]); // => true
isDefinitionNode(document); // => false

isExecutableDefinitionNode()

Returns true when the AST node is an executable definition node.

Signature:

isExecutableDefinitionNode(
  node: ASTNode,
): node is ExecutableDefinitionNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is ExecutableDefinitionNodeTrue when the AST node is an executable definition node.

Example
import { parse, isExecutableDefinitionNode } from 'graphql/language';
 
const query = parse('{ hello }');
const schema = parse('type Query { hello: String }');
 
isExecutableDefinitionNode(query.definitions[0]); // => true
isExecutableDefinitionNode(schema.definitions[0]); // => false

isSubscriptionOperationDefinitionNode()

A type predicate for SubscriptionOperationDefinitionNode. Useful anywhere that must distinguish subscription operations from queries and mutations, such as the subscription execution pipeline which routes events through a different code path.

Signature:

isSubscriptionOperationDefinitionNode(
  node: OperationDefinitionNode,
): node is SubscriptionOperationDefinitionNode;

Arguments
NameTypeDescription
nodeOperationDefinitionNodeOperation definition node to test.

Returns
TypeDescription
node is SubscriptionOperationDefinitionNodeTrue when the operation definition is a subscription.

Example
import { parse, isSubscriptionOperationDefinitionNode } from 'graphql/language';
 
const subscription = parse('subscription { greeting }').definitions[0];
const query = parse('{ greeting }').definitions[0];
 
isSubscriptionOperationDefinitionNode(subscription); // => true
isSubscriptionOperationDefinitionNode(query); // => false

isSelectionNode()

Returns true when the AST node is a selection node.

Signature:

isSelectionNode(
  node: ASTNode,
): node is SelectionNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is SelectionNodeTrue when the AST node is a selection node.

Example
import { Kind, isSelectionNode } from 'graphql/language';
 
const field = { kind: Kind.FIELD, name: { kind: Kind.NAME, value: 'hello' } };
const document = { kind: Kind.DOCUMENT, definitions: [] };
 
isSelectionNode(field); // => true
isSelectionNode(document); // => false

isValueNode()

Returns true when the AST node is a value node.

Signature:

isValueNode(
  node: ASTNode,
): node is ValueNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is ValueNodeTrue when the AST node is a value node.

Example
import { parseType, parseValue, isValueNode } from 'graphql/language';
 
const value = parseValue('[42]');
const type = parseType('[String!]');
 
isValueNode(value); // => true
isValueNode(type); // => false

isConstValueNode()

Returns true when the AST node is a constant value node.

Signature:

isConstValueNode(
  node: ASTNode,
): node is ConstValueNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is ConstValueNodeTrue when the AST node is a constant value node.

Example
import { parseConstValue, parseValue, isConstValueNode } from 'graphql/language';
 
const value = parseConstValue('[42]');
const variable = parseValue('$id');
 
isConstValueNode(value); // => true
isConstValueNode(variable); // => false

isTypeNode()

Returns true when the AST node is a type node.

Signature:

isTypeNode(
  node: ASTNode,
): node is TypeNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is TypeNodeTrue when the AST node is a type node.

Example
import { parseType, parseValue, isTypeNode } from 'graphql/language';
 
const type = parseType('[String!]');
const value = parseValue('[42]');
 
isTypeNode(type); // => true
isTypeNode(value); // => false

isTypeSystemDefinitionNode()

Returns true when the AST node is a type system definition node.

Signature:

isTypeSystemDefinitionNode(
  node: ASTNode,
): node is TypeSystemDefinitionNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is TypeSystemDefinitionNodeTrue when the AST node is a type system definition node.

Example
import { parse, isTypeSystemDefinitionNode } from 'graphql/language';
 
const schema = parse('type Query { hello: String }');
const query = parse('{ hello }');
 
isTypeSystemDefinitionNode(schema.definitions[0]); // => true
isTypeSystemDefinitionNode(query.definitions[0]); // => false

isTypeDefinitionNode()

Returns true when the AST node is a type definition node.

Signature:

isTypeDefinitionNode(
  node: ASTNode,
): node is TypeDefinitionNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is TypeDefinitionNodeTrue when the AST node is a type definition node.

Example
import { parse, isTypeDefinitionNode } from 'graphql/language';
 
const typeDefinition = parse('type Query { hello: String }');
const directiveDefinition = parse('directive @cache on FIELD');
 
isTypeDefinitionNode(typeDefinition.definitions[0]); // => true
isTypeDefinitionNode(directiveDefinition.definitions[0]); // => false

isTypeSystemExtensionNode()

Returns true when the AST node is a type system extension node.

Signature:

isTypeSystemExtensionNode(
  node: ASTNode,
): node is TypeSystemExtensionNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is TypeSystemExtensionNodeTrue when the AST node is a type system extension node.

Example
import { parse, isTypeSystemExtensionNode } from 'graphql/language';
 
const extension = parse('extend type Query { hello: String }');
const definition = parse('type Query { hello: String }');
 
isTypeSystemExtensionNode(extension.definitions[0]); // => true
isTypeSystemExtensionNode(definition.definitions[0]); // => false

isTypeExtensionNode()

Returns true when the AST node is a type extension node.

Signature:

isTypeExtensionNode(
  node: ASTNode,
): node is TypeExtensionNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is TypeExtensionNodeTrue when the AST node is a type extension node.

Example
import { parse, isTypeExtensionNode } from 'graphql/language';
 
const extension = parse('extend type Query { hello: String }');
const schemaExtension = parse('extend schema { query: Query }');
 
isTypeExtensionNode(extension.definitions[0]); // => true
isTypeExtensionNode(schemaExtension.definitions[0]); // => false

isSchemaCoordinateNode()

Returns true when the AST node is a schema coordinate node.

Signature:

isSchemaCoordinateNode(
  node: ASTNode,
): node is SchemaCoordinateNode;

Arguments
NameTypeDescription
nodeASTNodeThe AST node to test.

Returns
TypeDescription
node is SchemaCoordinateNodeTrue when the AST node is a schema coordinate node.

Example
import {
  parse,
  parseSchemaCoordinate,
  isSchemaCoordinateNode,
} from 'graphql/language';
 
const coordinate = parseSchemaCoordinate('Query.hero');
const document = parse('{ hero }');
 
isSchemaCoordinateNode(coordinate); // => true
isSchemaCoordinateNode(document); // => false

Category: Printing

Functions:
print()

Functions

print()

Converts an AST into a string, using one set of reasonable formatting rules.

Signature:

print(ast: ASTNode): string;

Arguments
NameTypeDescription
astASTNodeThe GraphQL AST node to print.

Returns
TypeDescription
stringA stable string representation of the AST.

Example
import { parse, print } from 'graphql';
 
const ast = parse('{ hero { name } }');
const text = print(ast);
 
text; // => '{\n  hero {\n    name\n  }\n}'

Category: Visiting

Functions

visitInParallel()

Creates a new visitor instance which delegates to many visitors to run in parallel. Each visitor will be visited for each node before moving on.

If a prior visitor edits a node, no following visitors will see that node.

Signature:

visitInParallel(
  visitors: readonly ASTVisitor[],
): ASTVisitor;

Arguments
NameTypeDescription
visitorsreadonly ASTVisitor[]The visitors to merge into one parallel visitor.

Returns
TypeDescription
ASTVisitorA visitor that delegates traversal to each provided visitor.

Example
import { parse, visit, visitInParallel } from 'graphql/language';
 
const document = parse('{ hero { name } }');
const events = [];
 
visit(
  document,
  visitInParallel([
    { Field: (node) => { events.push(`field:${node.name.value}`); } },
    { Name: (node) => { events.push(`name:${node.value}`); } },
  ]),
);
 
events; // => ['field:hero', 'name:hero', 'field:name', 'name:name']

getEnterLeaveForKind()

Given a visitor instance and a node kind, return EnterLeaveVisitor for that kind.

Signature:

getEnterLeaveForKind(
  visitor: ASTVisitor,
  kind: Kind,
): {
  enter?: ASTVisitFn<ASTNode> | undefined;
  leave?: ASTVisitFn<ASTNode> | undefined;
};

Arguments
NameTypeDescription
visitorASTVisitorThe visitor object to inspect.
kindKindThe AST node kind to resolve handlers for.

Returns
TypeDescription
{ enter?: ASTVisitFn<ASTNode> | undefined; leave?: ASTVisitFn<ASTNode> | undefined; }The enter and leave handlers that apply for the given node kind.

Example
import { Kind, getEnterLeaveForKind } from 'graphql/language';
 
const handlers = getEnterLeaveForKind({ Field: () => {} }, Kind.FIELD);
 
typeof handlers.enter; // => 'function'
handlers.leave; // => undefined

Constants

BREAK

A value that can be returned from a visitor function to stop traversal.


Type
unknown

Types

ASTVisitor

Type alias. A visitor defines the callbacks called during AST traversal.

type ASTVisitor =
  | {
      enter?:
        | ASTVisitFn<ASTNode>
        | undefined;
      leave?:
        | ASTVisitFn<ASTNode>
        | undefined;
    }
  | {
      readonly [NodeT in ASTNode as NodeT['kind']]?:
        | ASTVisitFn<NodeT>
        | EnterLeaveVisitor<NodeT>;
    };

ASTVisitFn

Type alias. A visitor is composed of visit functions called for each node during traversal.


Type Parameters
NameConstraintDefaultDescription
TVisitedNodeASTNodeAST node type handled by this visitor function.
type ASTVisitFn<TVisitedNode extends ASTNode> = (
  node: TVisitedNode,
  key: string | number | undefined,
  parent:
    | ASTNode
    | ReadonlyArray<ASTNode>
    | undefined,
  path: ReadonlyArray<string | number>,
  ancestors: ReadonlyArray<
    ASTNode | ReadonlyArray<ASTNode>
  >,
) => any;

ASTVisitorKeyMap

Type alias. A visitor key map describes the traversable child properties for each node kind.

type ASTVisitorKeyMap = mapped object;