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
- start: int
- class graphql.language.Node(**kwargs: Any)
Bases:
object
AST nodes
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc',)
- kind: str = 'ast'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
Each kind of AST node has its own class:
- class graphql.language.ArgumentNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'name', 'value')
- kind: str = 'argument'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.BooleanValueNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'value')
- kind: str = 'boolean_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- value: bool
- class graphql.language.ConstArgumentNode(**kwargs: Any)
Bases:
ArgumentNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'name', 'value', 'name', 'value')
- kind: str = 'argument'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ConstDirectiveNode(**kwargs: Any)
Bases:
DirectiveNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: tuple[ConstArgumentNode, ...]
- keys: tuple[str, ...] = ('loc', 'arguments', 'name', 'arguments', 'name')
- kind: str = 'directive'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ConstListValueNode(**kwargs: Any)
Bases:
ListValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'values', 'values')
- kind: str = 'list_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- values: tuple[IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode, ...]
- class graphql.language.ConstObjectFieldNode(**kwargs: Any)
Bases:
ObjectFieldNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'name', 'value', 'name', 'value')
- kind: str = 'object_field'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ConstObjectValueNode(**kwargs: Any)
Bases:
ObjectValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- fields: tuple[ConstObjectFieldNode, ...]
- keys: tuple[str, ...] = ('loc', 'fields', 'fields')
- kind: str = 'object_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- graphql.language.ConstValueNode
alias of
IntValueNode
|FloatValueNode
|StringValueNode
|BooleanValueNode
|NullValueNode
|EnumValueNode
|ConstListValueNode
|ConstObjectValueNode
- class graphql.language.DefinitionNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc',)
- kind: str = 'definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.DirectiveDefinitionNode(**kwargs: Any)
Bases:
TypeSystemDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: tuple[InputValueDefinitionNode, ...]
- description: StringValueNode | None
- keys: tuple[str, ...] = ('loc', 'arguments', 'description', 'locations', 'name', 'repeatable')
- kind: str = 'directive_definition'
- repeatable: bool
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.DirectiveNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: tuple[ArgumentNode, ...]
- keys: tuple[str, ...] = ('loc', 'arguments', 'name')
- kind: str = 'directive'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.DocumentNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- definitions: tuple[DefinitionNode, ...]
- keys: tuple[str, ...] = ('loc', 'definitions')
- kind: str = 'document'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.EnumTypeDefinitionNode(**kwargs: Any)
Bases:
TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'name', 'values')
- kind: str = 'enum_type_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- values: tuple[EnumValueDefinitionNode, ...]
- class graphql.language.EnumTypeExtensionNode(**kwargs: Any)
Bases:
TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name', 'values')
- kind: str = 'enum_type_extension'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- values: tuple[EnumValueDefinitionNode, ...]
- class graphql.language.EnumValueDefinitionNode(**kwargs: Any)
Bases:
DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'name')
- kind: str = 'enum_value_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.EnumValueNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'value')
- kind: str = 'enum_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- value: str
- class graphql.language.ErrorBoundaryNode(**kwargs: Any)
Bases:
NullabilityAssertionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'nullability_assertion', 'nullability_assertion')
- kind: str = 'error_boundary'
- nullability_assertion: ListNullabilityOperatorNode
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ExecutableDefinitionNode(**kwargs: Any)
Bases:
DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[DirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name', 'selection_set', 'variable_definitions')
- kind: str = 'executable_definition'
- selection_set: SelectionSetNode
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- variable_definitions: tuple[VariableDefinitionNode, ...]
- class graphql.language.FieldDefinitionNode(**kwargs: Any)
Bases:
DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: tuple[InputValueDefinitionNode, ...]
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'arguments', 'description', 'directives', 'name', 'type')
- kind: str = 'field_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.FieldNode(**kwargs: Any)
Bases:
SelectionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: tuple[ArgumentNode, ...]
- directives: tuple[DirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'alias', 'arguments', 'name', 'nullability_assertion', 'selection_set')
- kind: str = 'field'
- nullability_assertion: NullabilityAssertionNode
- selection_set: SelectionSetNode | None
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.FloatValueNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'value')
- kind: str = 'float_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- value: str
- class graphql.language.FragmentDefinitionNode(**kwargs: Any)
Bases:
ExecutableDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[DirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name', 'selection_set', 'variable_definitions', 'type_condition')
- kind: str = 'fragment_definition'
- selection_set: SelectionSetNode
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- type_condition: NamedTypeNode
- variable_definitions: tuple[VariableDefinitionNode, ...]
- class graphql.language.FragmentSpreadNode(**kwargs: Any)
Bases:
SelectionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[DirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name')
- kind: str = 'fragment_spread'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.InlineFragmentNode(**kwargs: Any)
Bases:
SelectionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[DirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'selection_set', 'type_condition')
- kind: str = 'inline_fragment'
- selection_set: SelectionSetNode
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- type_condition: NamedTypeNode
- class graphql.language.InputObjectTypeDefinitionNode(**kwargs: Any)
Bases:
TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- fields: tuple[InputValueDefinitionNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'name', 'fields')
- kind: str = 'input_object_type_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.InputObjectTypeExtensionNode(**kwargs: Any)
Bases:
TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[ConstDirectiveNode, ...]
- fields: tuple[InputValueDefinitionNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name', 'fields')
- kind: str = 'input_object_type_extension'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.InputValueDefinitionNode(**kwargs: Any)
Bases:
DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- default_value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode | None
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'default_value', 'description', 'directives', 'name', 'type')
- kind: str = 'input_value_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.IntValueNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'value')
- kind: str = 'int_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- value: str
- class graphql.language.InterfaceTypeDefinitionNode(**kwargs: Any)
Bases:
TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- fields: tuple[FieldDefinitionNode, ...]
- interfaces: tuple[NamedTypeNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'name', 'fields', 'interfaces')
- kind: str = 'interface_type_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.InterfaceTypeExtensionNode(**kwargs: Any)
Bases:
TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[ConstDirectiveNode, ...]
- fields: tuple[FieldDefinitionNode, ...]
- interfaces: tuple[NamedTypeNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name', 'fields', 'interfaces')
- kind: str = 'interface_type_extension'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ListNullabilityOperatorNode(**kwargs: Any)
Bases:
NullabilityAssertionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'nullability_assertion', 'nullability_assertion')
- kind: str = 'list_nullability_operator'
- nullability_assertion: NullabilityAssertionNode | None
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ListTypeNode(**kwargs: Any)
Bases:
TypeNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'type')
- kind: str = 'list_type'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ListValueNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'values')
- kind: str = 'list_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.NameNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'value')
- kind: str = 'name'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- value: str
- class graphql.language.NamedTypeNode(**kwargs: Any)
Bases:
TypeNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'name')
- kind: str = 'named_type'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.NonNullAssertionNode(**kwargs: Any)
Bases:
NullabilityAssertionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'nullability_assertion', 'nullability_assertion')
- kind: str = 'non_null_assertion'
- nullability_assertion: ListNullabilityOperatorNode
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.NonNullTypeNode(**kwargs: Any)
Bases:
TypeNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'type')
- kind: str = 'non_null_type'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- type: NamedTypeNode | ListTypeNode
- class graphql.language.NullabilityAssertionNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'nullability_assertion')
- kind: str = 'nullability_assertion'
- nullability_assertion: NullabilityAssertionNode | None
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.NullValueNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc',)
- kind: str = 'null_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ObjectFieldNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'name', 'value')
- kind: str = 'object_field'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ObjectTypeDefinitionNode(**kwargs: Any)
Bases:
TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- fields: tuple[FieldDefinitionNode, ...]
- interfaces: tuple[NamedTypeNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'name', 'fields', 'interfaces')
- kind: str = 'object_type_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ObjectTypeExtensionNode(**kwargs: Any)
Bases:
TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[ConstDirectiveNode, ...]
- fields: tuple[FieldDefinitionNode, ...]
- interfaces: tuple[NamedTypeNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name', 'fields', 'interfaces')
- kind: str = 'object_type_extension'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ObjectValueNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- fields: tuple[ObjectFieldNode, ...]
- keys: tuple[str, ...] = ('loc', 'fields')
- kind: str = 'object_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.OperationDefinitionNode(**kwargs: Any)
Bases:
ExecutableDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[DirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name', 'selection_set', 'variable_definitions', 'operation')
- kind: str = 'operation_definition'
- operation: OperationType
- selection_set: SelectionSetNode
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- variable_definitions: tuple[VariableDefinitionNode, ...]
- class graphql.language.OperationType(value)
Bases:
Enum
An enumeration.
- MUTATION = 'mutation'
- QUERY = 'query'
- SUBSCRIPTION = 'subscription'
- class graphql.language.OperationTypeDefinitionNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'operation', 'type')
- kind: str = 'operation_type_definition'
- operation: OperationType
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- type: NamedTypeNode
- class graphql.language.ScalarTypeDefinitionNode(**kwargs: Any)
Bases:
TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'name')
- kind: str = 'scalar_type_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.ScalarTypeExtensionNode(**kwargs: Any)
Bases:
TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name')
- kind: str = 'scalar_type_extension'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.SchemaDefinitionNode(**kwargs: Any)
Bases:
TypeSystemDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'operation_types')
- kind: str = 'schema_definition'
- operation_types: tuple[OperationTypeDefinitionNode, ...]
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.SchemaExtensionNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'operation_types')
- kind: str = 'schema_extension'
- operation_types: tuple[OperationTypeDefinitionNode, ...]
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.SelectionNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[DirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives')
- kind: str = 'selection'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.SelectionSetNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'selections')
- kind: str = 'selection_set'
- selections: tuple[SelectionNode, ...]
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.StringValueNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- block: bool | None
- keys: tuple[str, ...] = ('loc', 'block', 'value')
- kind: str = 'string_value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- value: str
- class graphql.language.TypeDefinitionNode(**kwargs: Any)
Bases:
TypeSystemDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[DirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'name')
- kind: str = 'type_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.TypeExtensionNode(**kwargs: Any)
Bases:
TypeSystemDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name')
- kind: str = 'type_extension'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.TypeNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc',)
- kind: str = 'type'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.TypeSystemDefinitionNode(**kwargs: Any)
Bases:
DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc',)
- kind: str = 'type_system_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- graphql.language.TypeSystemExtensionNode
alias of
SchemaExtensionNode
|TypeExtensionNode
- class graphql.language.UnionTypeDefinitionNode(**kwargs: Any)
Bases:
TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: StringValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'description', 'directives', 'name', 'types')
- kind: str = 'union_type_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- types: tuple[NamedTypeNode, ...]
- class graphql.language.UnionTypeExtensionNode(**kwargs: Any)
Bases:
TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'directives', 'name', 'types')
- kind: str = 'union_type_extension'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- types: tuple[NamedTypeNode, ...]
- class graphql.language.ValueNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc',)
- kind: str = 'value'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- class graphql.language.VariableDefinitionNode(**kwargs: Any)
Bases:
Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- default_value: IntValueNode | FloatValueNode | StringValueNode | BooleanValueNode | NullValueNode | EnumValueNode | ConstListValueNode | ConstObjectValueNode | None
- directives: tuple[ConstDirectiveNode, ...]
- keys: tuple[str, ...] = ('loc', 'default_value', 'directives', 'type', 'variable')
- kind: str = 'variable_definition'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
- variable: VariableNode
- class graphql.language.VariableNode(**kwargs: Any)
Bases:
ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: tuple[str, ...] = ('loc', 'name')
- kind: str = 'variable'
- to_dict(locations: bool = False) dict
Concert node to a dictionary.
Directive locations are specified using the following enumeration:
- class graphql.language.DirectiveLocation(value)
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'
- 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.
- create_token(kind: TokenKind, start: int, end: int, value: str | None = None) Token
Create a token with line and column location information.
- 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_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_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.
- class graphql.language.TokenKind(value)
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 = '|'
- QUESTION_MARK = '?'
- 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.
- __init__(kind: TokenKind, start: int, end: int, line: int, column: int, value: str | None = None) None
- column: int
- property desc: str
A helper property to describe a token as a string for debugging
- end: int
- line: int
- 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.
- __init__()
- column: int
Alias for field number 1
- count(value, /)
Return number of occurrences of value.
- property formatted: graphql.language.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
Parser
- graphql.language.parse(source: Source | str, no_location: bool = False, max_tokens: int | None = None, allow_legacy_fragment_variables: bool = False, experimental_client_controlled_nullability: 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.
Legacy feature (will be removed in v3.3):
If
allow_legacy_fragment_variables
is set toTrue
, the parser will understand and parse variable definitions contained in a fragment definition. They’ll be represented in thevariable_definitions
field of theFragmentDefinitionNode
.The syntax is identical to normal, query-defined variables. For example:
fragment A($var: Boolean = false) on T { ... }
EXPERIMENTAL:
If enabled, the parser will understand and parse Client Controlled Nullability Designators contained in Fields. They’ll be represented in the
nullability_assertion
field of theFieldNode
.The syntax looks like the following:
{ nullableField! nonNullableField? nonNullableSelectionSet? { childField! } }
Note: this feature is experimental and may change or be removed in the future.
- graphql.language.parse_type(source: Source | str, no_location: bool = False, max_tokens: int | None = None, allow_legacy_fragment_variables: 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, allow_legacy_fragment_variables: 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.
Consider providing the results to the utility function:
value_from_ast()
.
- graphql.language.parse_const_value(source: Source | str, no_location: bool = False, max_tokens: int | None = None, allow_legacy_fragment_variables: 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
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.
- __init__(body: str, name: str = 'GraphQL request', location_offset: SourceLocation = (1, 1)) None
Initialize source input.
The
name
andlocation_offset
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 namedFoo.graphql
, it might be useful forname
to be"Foo.graphql"
and location to be(40, 0)
.The
line
andcolumn
attributes inlocation_offset
are 1-indexed.
- 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 methodsenter_field()
and/orleave_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
- __init__() None
- 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
- __init__(visitors: Collection[Visitor]) None
Create a new visitor from the given list of parallel visitors.
- enter_leave_map: dict[str, EnterLeaveVisitor]
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
The module also exports the following enumeration that can be used as the return type
for Visitor
methods:
- class graphql.language.visitor.VisitorActionEnum(value)
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.