Language

GraphQL Language

The graphql.language package is responsible for parsing and operating on the GraphQL language.

AST

class graphql.language.Location(start_token: Token, end_token: Token, source: Source)

Bases: object

AST Location

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

end: int
end_token: Token
source: Source
start: int
start_token: Token
class graphql.language.Node(*, loc: Location | None = None)

Bases: object

AST nodes

keys: ClassVar[tuple[str, ...]] = ('loc',)
kind: ClassVar[str] = 'ast'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

Each kind of AST node has its own class:

class graphql.language.ArgumentNode(*, loc: 'Location | None' = None, name: 'NameNode', value: 'ValueNode')

Bases: Node

keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'value')
kind: ClassVar[str] = 'argument'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: ValueNode
class graphql.language.BooleanValueNode(*, loc: 'Location | None' = None, value: 'bool')

Bases: ValueNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'value')
kind: ClassVar[str] = 'boolean_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: bool
class graphql.language.ConstArgumentNode(*, loc: 'Location | None' = None, name: 'NameNode', value: 'ConstValueNode')

Bases: ArgumentNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'value')
kind: ClassVar[str] = 'argument'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode
class graphql.language.ConstDirectiveNode(*, loc: 'Location | None' = None, name: 'NameNode', arguments: 'tuple[ConstArgumentNode, ...] | None' = None)

Bases: DirectiveNode

arguments: tuple[ConstArgumentNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'arguments')
kind: ClassVar[str] = 'directive'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.ConstListValueNode(*, loc: 'Location | None' = None, values: 'tuple[ConstValueNode, ...]' = ())

Bases: ListValueNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'values')
kind: ClassVar[str] = 'list_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

values: tuple[IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode, ...] = ()
class graphql.language.ConstObjectFieldNode(*, loc: 'Location | None' = None, name: 'NameNode', value: 'ConstValueNode')

Bases: ObjectFieldNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'value')
kind: ClassVar[str] = 'object_field'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode
class graphql.language.ConstObjectValueNode(*, loc: 'Location | None' = None, fields: 'tuple[ConstObjectFieldNode, ...]' = ())

Bases: ObjectValueNode

fields: tuple[ConstObjectFieldNode, ...] = ()
keys: ClassVar[tuple[str, ...]] = ('loc', 'fields')
kind: ClassVar[str] = 'object_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

graphql.language.ConstValueNode

alias of IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode

class graphql.language.DefinitionNode(*, loc: Location | None = None)

Bases: Node

Base class for all definition nodes.

keys: ClassVar[tuple[str, ...]] = ('loc',)
kind: ClassVar[str] = 'definition'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.DirectiveDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', locations: 'tuple[NameNode, ...]', description: 'StringValueNode | None' = None, arguments: 'tuple[InputValueDefinitionNode, ...] | None' = None, repeatable: 'bool' = False)

Bases: TypeSystemDefinitionNode

arguments: tuple[InputValueDefinitionNode, ...] | None = None
description: StringValueNode | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'locations', 'description', 'arguments', 'repeatable')
kind: ClassVar[str] = 'directive_definition'
loc: Location | None = None
locations: tuple[NameNode, ...]
name: NameNode
repeatable: bool = False
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.DirectiveNode(*, loc: 'Location | None' = None, name: 'NameNode', arguments: 'tuple[ArgumentNode, ...] | None' = None)

Bases: Node

arguments: tuple[ArgumentNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'arguments')
kind: ClassVar[str] = 'directive'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.DocumentNode(*, loc: 'Location | None' = None, definitions: 'tuple[DefinitionNode, ...]' = ())

Bases: Node

definitions: tuple[DefinitionNode, ...] = ()
keys: ClassVar[tuple[str, ...]] = ('loc', 'definitions')
kind: ClassVar[str] = 'document'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

token_count: ClassVar[int] = 0
class graphql.language.EnumTypeDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', description: 'StringValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None, values: 'tuple[EnumValueDefinitionNode, ...] | None' = None)

Bases: TypeDefinitionNode

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'description', 'directives', 'values')
kind: ClassVar[str] = 'enum_type_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

values: tuple[EnumValueDefinitionNode, ...] | None = None
class graphql.language.EnumTypeExtensionNode(*, loc: 'Location | None' = None, name: 'NameNode', directives: 'tuple[ConstDirectiveNode, ...] | None' = None, values: 'tuple[EnumValueDefinitionNode, ...] | None' = None)

Bases: TypeExtensionNode

directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'directives', 'values')
kind: ClassVar[str] = 'enum_type_extension'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

values: tuple[EnumValueDefinitionNode, ...] | None = None
class graphql.language.EnumValueDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', description: 'StringValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None)

Bases: DefinitionNode

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'description', 'directives')
kind: ClassVar[str] = 'enum_value_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.EnumValueNode(*, loc: 'Location | None' = None, value: 'str')

Bases: ValueNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'value')
kind: ClassVar[str] = 'enum_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: str
class graphql.language.ExecutableDefinitionNode(*, loc: Location | None = None, selection_set: SelectionSetNode, description: StringValueNode | None = None, name: NameNode | None = None, variable_definitions: tuple[VariableDefinitionNode, ...] | None = None, directives: tuple[DirectiveNode, ...] | None = None)

Bases: DefinitionNode

Base class for executable definition nodes.

description: StringValueNode | None = None
directives: tuple[DirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'selection_set', 'description', 'name', 'variable_definitions', 'directives')
kind: ClassVar[str] = 'executable_definition'
loc: Location | None = None
name: NameNode | None = None
selection_set: SelectionSetNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

variable_definitions: tuple[VariableDefinitionNode, ...] | None = None
class graphql.language.FieldDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', type: 'TypeNode', description: 'StringValueNode | None' = None, arguments: 'tuple[InputValueDefinitionNode, ...] | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None)

Bases: DefinitionNode

arguments: tuple[InputValueDefinitionNode, ...] | None = None
description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'type', 'description', 'arguments', 'directives')
kind: ClassVar[str] = 'field_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

type: TypeNode
class graphql.language.FieldNode(*, loc: 'Location | None' = None, directives: 'tuple[DirectiveNode, ...] | None' = None, name: 'NameNode', alias: 'NameNode | None' = None, arguments: 'tuple[ArgumentNode, ...] | None' = None, selection_set: 'SelectionSetNode | None' = None)

Bases: SelectionNode

alias: NameNode | None = None
arguments: tuple[ArgumentNode, ...] | None = None
directives: tuple[DirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'directives', 'name', 'alias', 'arguments', 'selection_set')
kind: ClassVar[str] = 'field'
loc: Location | None = None
name: NameNode
selection_set: SelectionSetNode | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.FloatValueNode(*, loc: 'Location | None' = None, value: 'str')

Bases: ValueNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'value')
kind: ClassVar[str] = 'float_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: str
class graphql.language.FragmentArgumentNode(*, loc: 'Location | None' = None, name: 'NameNode', value: 'ValueNode')

Bases: Node

keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'value')
kind: ClassVar[str] = 'fragment_argument'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: ValueNode
class graphql.language.FragmentDefinitionNode(*, loc: 'Location | None' = None, selection_set: 'SelectionSetNode', description: 'StringValueNode | None' = None, name: 'NameNode' = None, variable_definitions: 'tuple[VariableDefinitionNode, ...] | None' = None, directives: 'tuple[DirectiveNode, ...] | None' = None, type_condition: 'NamedTypeNode')

Bases: ExecutableDefinitionNode

description: StringValueNode | None = None
directives: tuple[DirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'selection_set', 'description', 'name', 'variable_definitions', 'directives', 'type_condition')
kind: ClassVar[str] = 'fragment_definition'
loc: Location | None = None
name: NameNode = None
selection_set: SelectionSetNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

type_condition: NamedTypeNode
variable_definitions: tuple[VariableDefinitionNode, ...] | None = None
class graphql.language.FragmentSpreadNode(*, loc: 'Location | None' = None, directives: 'tuple[DirectiveNode, ...] | None' = None, name: 'NameNode', arguments: 'tuple[FragmentArgumentNode, ...] | None' = None)

Bases: SelectionNode

arguments: tuple[FragmentArgumentNode, ...] | None = None
directives: tuple[DirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'directives', 'name', 'arguments')
kind: ClassVar[str] = 'fragment_spread'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.InlineFragmentNode(*, loc: 'Location | None' = None, directives: 'tuple[DirectiveNode, ...] | None' = None, selection_set: 'SelectionSetNode', type_condition: 'NamedTypeNode | None' = None)

Bases: SelectionNode

directives: tuple[DirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'directives', 'selection_set', 'type_condition')
kind: ClassVar[str] = 'inline_fragment'
loc: Location | None = None
selection_set: SelectionSetNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

type_condition: NamedTypeNode | None = None
class graphql.language.InputObjectTypeDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', description: 'StringValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None, fields: 'tuple[InputValueDefinitionNode, ...] | None' = None)

Bases: TypeDefinitionNode

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
fields: tuple[InputValueDefinitionNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'description', 'directives', 'fields')
kind: ClassVar[str] = 'input_object_type_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.InputObjectTypeExtensionNode(*, loc: 'Location | None' = None, name: 'NameNode', directives: 'tuple[ConstDirectiveNode, ...] | None' = None, fields: 'tuple[InputValueDefinitionNode, ...] | None' = None)

Bases: TypeExtensionNode

directives: tuple[ConstDirectiveNode, ...] | None = None
fields: tuple[InputValueDefinitionNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'directives', 'fields')
kind: ClassVar[str] = 'input_object_type_extension'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.InputValueDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', type: 'TypeNode', description: 'StringValueNode | None' = None, default_value: 'ConstValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None)

Bases: DefinitionNode

default_value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode | None = None
description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'type', 'description', 'default_value', 'directives')
kind: ClassVar[str] = 'input_value_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

type: TypeNode
class graphql.language.IntValueNode(*, loc: 'Location | None' = None, value: 'str')

Bases: ValueNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'value')
kind: ClassVar[str] = 'int_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: str
class graphql.language.InterfaceTypeDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', description: 'StringValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None, interfaces: 'tuple[NamedTypeNode, ...] | None' = None, fields: 'tuple[FieldDefinitionNode, ...] | None' = None)

Bases: TypeDefinitionNode

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
fields: tuple[FieldDefinitionNode, ...] | None = None
interfaces: tuple[NamedTypeNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'description', 'directives', 'interfaces', 'fields')
kind: ClassVar[str] = 'interface_type_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.InterfaceTypeExtensionNode(*, loc: 'Location | None' = None, name: 'NameNode', directives: 'tuple[ConstDirectiveNode, ...] | None' = None, interfaces: 'tuple[NamedTypeNode, ...] | None' = None, fields: 'tuple[FieldDefinitionNode, ...] | None' = None)

Bases: TypeExtensionNode

directives: tuple[ConstDirectiveNode, ...] | None = None
fields: tuple[FieldDefinitionNode, ...] | None = None
interfaces: tuple[NamedTypeNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'directives', 'interfaces', 'fields')
kind: ClassVar[str] = 'interface_type_extension'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.ListTypeNode(*, loc: 'Location | None' = None, type: 'TypeNode')

Bases: TypeNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'type')
kind: ClassVar[str] = 'list_type'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

type: TypeNode
class graphql.language.ListValueNode(*, loc: 'Location | None' = None, values: 'tuple[ValueNode, ...]' = ())

Bases: ValueNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'values')
kind: ClassVar[str] = 'list_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

values: tuple[ValueNode, ...] = ()
class graphql.language.NameNode(*, loc: 'Location | None' = None, value: 'str')

Bases: Node

keys: ClassVar[tuple[str, ...]] = ('loc', 'value')
kind: ClassVar[str] = 'name'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: str
class graphql.language.NamedTypeNode(*, loc: 'Location | None' = None, name: 'NameNode')

Bases: TypeNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'name')
kind: ClassVar[str] = 'named_type'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.NonNullTypeNode(*, loc: 'Location | None' = None, type: 'NamedTypeNode | ListTypeNode')

Bases: TypeNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'type')
kind: ClassVar[str] = 'non_null_type'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

type: NamedTypeNode | ListTypeNode
class graphql.language.NullValueNode(*, loc: Location | None = None)

Bases: ValueNode

A null value node has no fields.

keys: ClassVar[tuple[str, ...]] = ('loc',)
kind: ClassVar[str] = 'null_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.ObjectFieldNode(*, loc: 'Location | None' = None, name: 'NameNode', value: 'ValueNode')

Bases: Node

keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'value')
kind: ClassVar[str] = 'object_field'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: ValueNode
class graphql.language.ObjectTypeDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', description: 'StringValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None, interfaces: 'tuple[NamedTypeNode, ...] | None' = None, fields: 'tuple[FieldDefinitionNode, ...] | None' = None)

Bases: TypeDefinitionNode

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
fields: tuple[FieldDefinitionNode, ...] | None = None
interfaces: tuple[NamedTypeNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'description', 'directives', 'interfaces', 'fields')
kind: ClassVar[str] = 'object_type_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.ObjectTypeExtensionNode(*, loc: 'Location | None' = None, name: 'NameNode', directives: 'tuple[ConstDirectiveNode, ...] | None' = None, interfaces: 'tuple[NamedTypeNode, ...] | None' = None, fields: 'tuple[FieldDefinitionNode, ...] | None' = None)

Bases: TypeExtensionNode

directives: tuple[ConstDirectiveNode, ...] | None = None
fields: tuple[FieldDefinitionNode, ...] | None = None
interfaces: tuple[NamedTypeNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'directives', 'interfaces', 'fields')
kind: ClassVar[str] = 'object_type_extension'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.ObjectValueNode(*, loc: 'Location | None' = None, fields: 'tuple[ObjectFieldNode, ...]' = ())

Bases: ValueNode

fields: tuple[ObjectFieldNode, ...] = ()
keys: ClassVar[tuple[str, ...]] = ('loc', 'fields')
kind: ClassVar[str] = 'object_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.OperationDefinitionNode(*, loc: 'Location | None' = None, selection_set: 'SelectionSetNode', description: 'StringValueNode | None' = None, name: 'NameNode | None' = None, variable_definitions: 'tuple[VariableDefinitionNode, ...] | None' = None, directives: 'tuple[DirectiveNode, ...] | None' = None, operation: 'OperationType')

Bases: ExecutableDefinitionNode

description: StringValueNode | None = None
directives: tuple[DirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'selection_set', 'description', 'name', 'variable_definitions', 'directives', 'operation')
kind: ClassVar[str] = 'operation_definition'
loc: Location | None = None
name: NameNode | None = None
operation: OperationType
selection_set: SelectionSetNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

variable_definitions: tuple[VariableDefinitionNode, ...] | None = None
class graphql.language.OperationType(*values)

Bases: Enum

MUTATION = 'mutation'
QUERY = 'query'
SUBSCRIPTION = 'subscription'
class graphql.language.OperationTypeDefinitionNode(*, loc: 'Location | None' = None, operation: 'OperationType', type: 'NamedTypeNode')

Bases: Node

keys: ClassVar[tuple[str, ...]] = ('loc', 'operation', 'type')
kind: ClassVar[str] = 'operation_type_definition'
loc: Location | None = None
operation: OperationType
to_dict(locations: bool = False) dict

Convert node to a dictionary.

type: NamedTypeNode
class graphql.language.ScalarTypeDefinitionNode(*, loc: Location | None = None, name: NameNode, description: StringValueNode | None = None, directives: tuple[ConstDirectiveNode, ...] | None = None)

Bases: TypeDefinitionNode

Scalar type definition node - inherits name, description, directives.

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'description', 'directives')
kind: ClassVar[str] = 'scalar_type_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.ScalarTypeExtensionNode(*, loc: Location | None = None, name: NameNode, directives: tuple[ConstDirectiveNode, ...] | None = None)

Bases: TypeExtensionNode

Scalar type extension node - inherits name, directives.

directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'directives')
kind: ClassVar[str] = 'scalar_type_extension'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.SchemaDefinitionNode(*, loc: 'Location | None' = None, description: 'StringValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None, operation_types: 'tuple[OperationTypeDefinitionNode, ...]' = ())

Bases: TypeSystemDefinitionNode

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'description', 'directives', 'operation_types')
kind: ClassVar[str] = 'schema_definition'
loc: Location | None = None
operation_types: tuple[OperationTypeDefinitionNode, ...] = ()
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.SchemaExtensionNode(*, loc: 'Location | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None, operation_types: 'tuple[OperationTypeDefinitionNode, ...] | None' = None)

Bases: Node

directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'directives', 'operation_types')
kind: ClassVar[str] = 'schema_extension'
loc: Location | None = None
operation_types: tuple[OperationTypeDefinitionNode, ...] | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.SelectionNode(*, loc: Location | None = None, directives: tuple[DirectiveNode, ...] | None = None)

Bases: Node

Base class for selection nodes.

directives: tuple[DirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'directives')
kind: ClassVar[str] = 'selection'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.SelectionSetNode(*, loc: 'Location | None' = None, selections: 'tuple[SelectionNode, ...]' = ())

Bases: Node

keys: ClassVar[tuple[str, ...]] = ('loc', 'selections')
kind: ClassVar[str] = 'selection_set'
loc: Location | None = None
selections: tuple[SelectionNode, ...] = ()
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.StringValueNode(*, loc: 'Location | None' = None, value: 'str', block: 'bool | None' = None)

Bases: ValueNode

block: bool | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'value', 'block')
kind: ClassVar[str] = 'string_value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

value: str
class graphql.language.TypeDefinitionNode(*, loc: Location | None = None, name: NameNode, description: StringValueNode | None = None, directives: tuple[ConstDirectiveNode, ...] | None = None)

Bases: TypeSystemDefinitionNode

Base class for type definition nodes.

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'description', 'directives')
kind: ClassVar[str] = 'type_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.TypeExtensionNode(*, loc: Location | None = None, name: NameNode, directives: tuple[ConstDirectiveNode, ...] | None = None)

Bases: TypeSystemDefinitionNode

Base class for type extension nodes.

directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'directives')
kind: ClassVar[str] = 'type_extension'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.TypeNode(*, loc: Location | None = None)

Bases: Node

Base class for type nodes.

keys: ClassVar[tuple[str, ...]] = ('loc',)
kind: ClassVar[str] = 'type'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.TypeSystemDefinitionNode(*, loc: Location | None = None)

Bases: DefinitionNode

Base class for type system definition nodes.

keys: ClassVar[tuple[str, ...]] = ('loc',)
kind: ClassVar[str] = 'type_system_definition'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

graphql.language.TypeSystemExtensionNode

alias of SchemaExtensionNode | TypeExtensionNode

class graphql.language.UnionTypeDefinitionNode(*, loc: 'Location | None' = None, name: 'NameNode', description: 'StringValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None, types: 'tuple[NamedTypeNode, ...] | None' = None)

Bases: TypeDefinitionNode

description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'description', 'directives', 'types')
kind: ClassVar[str] = 'union_type_definition'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

types: tuple[NamedTypeNode, ...] | None = None
class graphql.language.UnionTypeExtensionNode(*, loc: 'Location | None' = None, name: 'NameNode', directives: 'tuple[ConstDirectiveNode, ...] | None' = None, types: 'tuple[NamedTypeNode, ...] | None' = None)

Bases: TypeExtensionNode

directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'name', 'directives', 'types')
kind: ClassVar[str] = 'union_type_extension'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

types: tuple[NamedTypeNode, ...] | None = None
class graphql.language.ValueNode(*, loc: Location | None = None)

Bases: Node

Base class for value nodes.

keys: ClassVar[tuple[str, ...]] = ('loc',)
kind: ClassVar[str] = 'value'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

class graphql.language.VariableDefinitionNode(*, loc: 'Location | None' = None, description: 'StringValueNode | None' = None, variable: 'VariableNode', type: 'TypeNode', default_value: 'ConstValueNode | None' = None, directives: 'tuple[ConstDirectiveNode, ...] | None' = None)

Bases: Node

default_value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode | None = None
description: StringValueNode | None = None
directives: tuple[ConstDirectiveNode, ...] | None = None
keys: ClassVar[tuple[str, ...]] = ('loc', 'description', 'variable', 'type', 'default_value', 'directives')
kind: ClassVar[str] = 'variable_definition'
loc: Location | None = None
to_dict(locations: bool = False) dict

Convert node to a dictionary.

type: TypeNode
variable: VariableNode
class graphql.language.VariableNode(*, loc: 'Location | None' = None, name: 'NameNode')

Bases: ValueNode

keys: ClassVar[tuple[str, ...]] = ('loc', 'name')
kind: ClassVar[str] = 'variable'
loc: Location | None = None
name: NameNode
to_dict(locations: bool = False) dict

Convert node to a dictionary.

Directive locations are specified using the following enumeration:

class graphql.language.DirectiveLocation(*values)

Bases: Enum

The enum type representing the directive location values.

ARGUMENT_DEFINITION = 'argument definition'
ENUM = 'enum'
ENUM_VALUE = 'enum value'
FIELD = 'field'
FIELD_DEFINITION = 'field definition'
FRAGMENT_DEFINITION = 'fragment definition'
FRAGMENT_SPREAD = 'fragment spread'
FRAGMENT_VARIABLE_DEFINITION = 'fragment variable definition'
INLINE_FRAGMENT = 'inline fragment'
INPUT_FIELD_DEFINITION = 'input field definition'
INPUT_OBJECT = 'input object'
INTERFACE = 'interface'
MUTATION = 'mutation'
OBJECT = 'object'
QUERY = 'query'
SCALAR = 'scalar'
SCHEMA = 'schema'
SUBSCRIPTION = 'subscription'
UNION = 'union'
VARIABLE_DEFINITION = 'variable definition'

You can also check the type of nodes with the following predicates:

graphql.language.is_definition_node(node: Node) TypeGuard[DefinitionNode]

Check whether the given node represents a definition.

graphql.language.is_executable_definition_node(node: Node) TypeGuard[ExecutableDefinitionNode]

Check whether the given node represents an executable definition.

graphql.language.is_selection_node(node: Node) TypeGuard[SelectionNode]

Check whether the given node represents a selection.

graphql.language.is_value_node(node: Node) TypeGuard[ValueNode]

Check whether the given node represents a value.

graphql.language.is_const_value_node(node: Node) TypeGuard[ValueNode]

Check whether the given node represents a constant value.

graphql.language.is_type_node(node: Node) TypeGuard[TypeNode]

Check whether the given node represents a type.

graphql.language.is_type_system_definition_node(node: Node) TypeGuard[TypeSystemDefinitionNode]

Check whether the given node represents a type system definition.

graphql.language.is_type_definition_node(node: Node) TypeGuard[TypeDefinitionNode]

Check whether the given node represents a type definition.

graphql.language.is_type_system_extension_node(node: Node) TypeGuard[SchemaExtensionNode | TypeExtensionNode]

Check whether the given node represents a type system extension.

graphql.language.is_type_extension_node(node: Node) TypeGuard[TypeExtensionNode]

Check whether the given node represents a type extension.

Lexer

class graphql.language.Lexer(source: Source)

Bases: object

GraphQL Lexer

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.

advance() Token

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

create_token(kind: TokenKind, start: int, end: int, value: str | None = None) Token

Create a token with line and column location information.

lookahead() Token

Look ahead and return the next non-ignored token, but do not change state.

print_code_point_at(location: int) str

Print the code point at the given location.

Prints the code point (or end of file reference) at a given location in a source for use in error messages.

Printable ASCII is printed quoted, while other points are printed in Unicode code point form (ie. U+1234).

read_block_string(start: int) Token

Read a block string token from the source file.

read_comment(start: int) Token

Read a comment token from the source file.

read_digits(start: int, first_char: str) int

Return the new position in the source after reading one or more digits.

read_escaped_character(position: int) EscapeSequence

Read escaped character sequence

read_escaped_unicode_fixed_width(position: int) EscapeSequence

Read escaped unicode with fixed width

read_escaped_unicode_variable_width(position: int) EscapeSequence

Read escaped unicode with variable width

read_name(start: int) Token

Read an alphanumeric + underscore name from the source.

read_next_token(start: int) Token

Get the next token from the source starting at the given position.

This skips over whitespace until it finds the next lexable token, then lexes punctuators immediately or calls the appropriate helper function for more complicated tokens.

read_number(start: int, first_char: str) Token

Reads a number token from the source file.

This can be either a FloatValue or an IntValue, depending on whether a FractionalPart or ExponentPart is encountered.

read_string(start: int) Token

Read a single-quote string token from the source file.

class graphql.language.TokenKind(*values)

Bases: Enum

The different kinds of tokens that the lexer emits

AMP = '&'
AT = '@'
BANG = '!'
BLOCK_STRING = 'BlockString'
BRACE_L = '{'
BRACE_R = '}'
BRACKET_L = '['
BRACKET_R = ']'
COLON = ':'
COMMENT = 'Comment'
DOLLAR = '$'
EOF = '<EOF>'
EQUALS = '='
FLOAT = 'Float'
INT = 'Int'
NAME = 'Name'
PAREN_L = '('
PAREN_R = ')'
PIPE = '|'
SOF = '<SOF>'
SPREAD = '...'
STRING = 'String'
class graphql.language.Token(kind: TokenKind, start: int, end: int, line: int, column: int, value: str | None = None)

Bases: object

AST Token

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

column: int
property desc: str

A helper property to describe a token as a string for debugging

end: int
kind: TokenKind
line: int
next: Token | None
prev: Token | None
start: int
value: str | None

Location

graphql.language.get_location(source: Source, position: int) SourceLocation

Get the line and column for a character position in the source.

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

class graphql.language.SourceLocation(line: int, column: int)

Bases: NamedTuple

Represents a location in a Source.

column: int

Alias for field number 1

count(value, /)

Return number of occurrences of value.

property formatted: FormattedSourceLocation

Get formatted source location.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

line: int

Alias for field number 0

graphql.language.print_location(location: Location) str

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

class graphql.language.FormattedSourceLocation

Bases: TypedDict

Formatted source location

column: int
line: int

Parser

graphql.language.parse(source: Source | str, no_location: bool = False, max_tokens: int | None = None, experimental_fragment_arguments: bool = False) DocumentNode

Given a GraphQL source, parse it into a Document.

Throws GraphQLError if a syntax error is encountered.

By default, the parser creates AST nodes that know the location in the source that they correspond to. The no_location option disables that behavior for performance or testing.

Parser 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.

EXPERIMENTAL:

If experimental_fragment_arguments is set to True, the parser will understand and parse fragment variable definitions and arguments on fragment spreads. Fragment variable definitions will be represented in the variable_definitions field of the FragmentDefinitionNode. Fragment spread arguments will be represented in the arguments field of the FragmentSpreadNode.

For example:

{
  t { ...A(var: true) }
}
fragment A($var: Boolean = false) on T {
  ...B(x: $var)
}
graphql.language.parse_type(source: Source | str, no_location: bool = False, max_tokens: int | None = None, experimental_fragment_arguments: bool = False) TypeNode

Parse the AST for a given string containing a GraphQL 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: value_from_ast().

graphql.language.parse_value(source: Source | str, no_location: bool = False, max_tokens: int | None = None, experimental_fragment_arguments: bool = False) ValueNode

Parse the AST for a given string containing a GraphQL 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.

graphql.language.parse_const_value(source: Source | str, no_location: bool = False, max_tokens: int | None = None, experimental_fragment_arguments: bool = False) IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode

Parse the AST for a given string containing a GraphQL constant value.

Similar to parse_value, but raises a arse error if it encounters a variable. The return type will be a constant value.

Printer

graphql.language.print_ast(ast: Node) str

Convert an AST into a string.

The conversion is done using a set of reasonable formatting rules.

Source

class graphql.language.Source(body: str, name: str = 'GraphQL request', location_offset: SourceLocation = (1, 1))

Bases: object

A representation of source input to GraphQL.

body
get_location(position: int) SourceLocation

Get source location.

location_offset
name
graphql.language.print_source_location(source: Source, source_location: SourceLocation) str

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

Visitor

graphql.language.visit(root: Node, visitor: Visitor, visitor_keys: dict[str, tuple[str, ...]] | None = None) Any

Visit each node in an AST.

visit() will walk through an AST using a depth-first traversal, calling the visitor’s enter methods at each node in the traversal, and calling the leave methods after visiting that node and all of its child nodes.

By returning different values from the enter and leave methods, the behavior of the visitor can be altered, including skipping over a sub-tree of the AST (by returning False), editing the AST by returning a value or None to remove the value, or to stop the whole traversal by returning BREAK.

When using visit() to edit an AST, the original AST will not be modified, and a new version of the AST with the changes applied will be returned from the visit function.

To customize the node attributes to be used for traversal, you can provide a dictionary visitor_keys mapping node kinds to node attributes.

class graphql.language.Visitor

Bases: object

Visitor that walks through an AST.

Visitors can define two generic methods “enter” and “leave”. The former will be called when a node is entered in the traversal, the latter is called after visiting the node and its child nodes. These methods have the following signature:

def enter(self, node, key, parent, path, ancestors):
    # The return value has the following meaning:
    # IDLE (None): no action
    # SKIP: skip visiting this node
    # BREAK: stop visiting altogether
    # REMOVE: delete this node
    # any other value: replace this node with the returned value
    return

def leave(self, node, key, parent, path, ancestors):
    # The return value has the following meaning:
    # IDLE (None) or SKIP: no action
    # BREAK: stop visiting altogether
    # REMOVE: delete this node
    # any other value: replace this node with the returned value
    return

The parameters have the following meaning:

Parameters:
  • node – The current node being visiting.

  • key – The index or key to this node from the parent node or Array.

  • parent – the parent immediately above this node, which may be an Array.

  • path – The key path to get to this node from the root node.

  • ancestors – All nodes and Arrays visited before reaching parent of this node. These correspond to array indices in path. Note: ancestors includes arrays which contain the parent of visited node.

You can also define node kind specific methods by suffixing them with an underscore followed by the kind of the node to be visited. For instance, to visit field nodes, you would define the methods enter_field() and/or leave_field(), with the same signature as above. If no kind specific method has been defined for a given node, the generic method is called.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
enter_leave_map: dict[str, EnterLeaveVisitor]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

Given a node kind, return the EnterLeaveVisitor for that kind.

class graphql.language.ParallelVisitor(visitors: Collection[Visitor])

Bases: Visitor

A Visitor 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.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
enter_leave_map: dict[str, EnterLeaveVisitor]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

Given a node kind, return the EnterLeaveVisitor for that kind.

skipping: list[Any]

The module also exports the following enumeration that can be used as the return type for Visitor methods:

class graphql.language.visitor.VisitorActionEnum(*values)

Bases: Enum

Special return values for the visitor methods.

You can also use the values of this enum directly.

BREAK = True
REMOVE = Ellipsis
SKIP = False

The module also exports the values of this enumeration directly. These can be used as return values of Visitor methods to signal particular actions:

graphql.language.BREAK (same as ``True``)

This return value signals that no further nodes shall be visited.

graphql.language.SKIP (same as ``False``)

This return value signals that the current node shall be skipped.

graphql.language.REMOVE (same as``Ellipsis``)

This return value signals that the current node shall be deleted.

graphql.language.IDLE = None

This return value signals that no additional action shall take place.