Language
GraphQL Language
The graphql.language
package is responsible for parsing and operating on the
GraphQL language.
AST
- class graphql.language.Location(start_token: graphql.language.ast.Token, end_token: graphql.language.ast.Token, source: graphql.language.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.
- __init__(start_token: graphql.language.ast.Token, end_token: graphql.language.ast.Token, source: graphql.language.source.Source) None
- end: int
- end_token: graphql.language.ast.Token
- source: graphql.language.source.Source
- start: int
- start_token: graphql.language.ast.Token
- 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'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
Each kind of AST node has its own class:
- class graphql.language.ArgumentNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'name', 'value')
- kind: str = 'argument'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.BooleanValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'value')
- kind: str = 'boolean_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- value: bool
- class graphql.language.ConstArgumentNode(**kwargs: Any)
Bases:
graphql.language.ast.ArgumentNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'name', 'value', 'name', 'value')
- kind: str = 'argument'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- value: Union[graphql.language.ast.IntValueNode, graphql.language.ast.FloatValueNode, graphql.language.ast.StringValueNode, graphql.language.ast.BooleanValueNode, graphql.language.ast.NullValueNode, graphql.language.ast.EnumValueNode, graphql.language.ast.ConstListValueNode, graphql.language.ast.ConstObjectValueNode]
- class graphql.language.ConstDirectiveNode(**kwargs: Any)
Bases:
graphql.language.ast.DirectiveNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: Tuple[graphql.language.ast.ConstArgumentNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'arguments', 'name', 'arguments')
- kind: str = 'directive'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.ConstListValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ListValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'values', 'values')
- kind: str = 'list_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- values: Tuple[Union[graphql.language.ast.IntValueNode, graphql.language.ast.FloatValueNode, graphql.language.ast.StringValueNode, graphql.language.ast.BooleanValueNode, graphql.language.ast.NullValueNode, graphql.language.ast.EnumValueNode, graphql.language.ast.ConstListValueNode, graphql.language.ast.ConstObjectValueNode], ...]
- class graphql.language.ConstObjectFieldNode(**kwargs: Any)
Bases:
graphql.language.ast.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'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- value: Union[graphql.language.ast.IntValueNode, graphql.language.ast.FloatValueNode, graphql.language.ast.StringValueNode, graphql.language.ast.BooleanValueNode, graphql.language.ast.NullValueNode, graphql.language.ast.EnumValueNode, graphql.language.ast.ConstListValueNode, graphql.language.ast.ConstObjectValueNode]
- class graphql.language.ConstObjectValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ObjectValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- fields: Tuple[graphql.language.ast.ConstObjectFieldNode, ...]
- keys: Tuple[str, ...] = ('loc', 'fields', 'fields')
- kind: str = 'object_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- graphql.language.ConstValueNode
alias of
Union
[graphql.language.ast.IntValueNode
,graphql.language.ast.FloatValueNode
,graphql.language.ast.StringValueNode
,graphql.language.ast.BooleanValueNode
,graphql.language.ast.NullValueNode
,graphql.language.ast.EnumValueNode
,graphql.language.ast.ConstListValueNode
,graphql.language.ast.ConstObjectValueNode
]
- class graphql.language.DefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc',)
- kind: str = 'definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.DirectiveDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeSystemDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: Tuple[graphql.language.ast.InputValueDefinitionNode, ...]
- description: Optional[graphql.language.ast.StringValueNode]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'arguments', 'repeatable', 'locations')
- kind: str = 'directive_definition'
- loc: Optional[graphql.language.ast.Location]
- locations: Tuple[graphql.language.ast.NameNode, ...]
- repeatable: bool
- to_dict(locations: bool = False) Dict
- class graphql.language.DirectiveNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: Tuple[graphql.language.ast.ArgumentNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'arguments')
- kind: str = 'directive'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.DocumentNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- definitions: Tuple[graphql.language.ast.DefinitionNode, ...]
- keys: Tuple[str, ...] = ('loc', 'definitions')
- kind: str = 'document'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.EnumTypeDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives', 'values')
- kind: str = 'enum_type_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- values: Tuple[graphql.language.ast.EnumValueDefinitionNode, ...]
- class graphql.language.EnumTypeExtensionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives', 'values')
- kind: str = 'enum_type_extension'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- values: Tuple[graphql.language.ast.EnumValueDefinitionNode, ...]
- class graphql.language.EnumValueDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives')
- kind: str = 'enum_value_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.EnumValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'value')
- kind: str = 'enum_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- value: str
- class graphql.language.ExecutableDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.DirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives', 'variable_definitions', 'selection_set')
- kind: str = 'executable_definition'
- loc: Optional[graphql.language.ast.Location]
- name: Optional[graphql.language.ast.NameNode]
- selection_set: graphql.language.ast.SelectionSetNode
- to_dict(locations: bool = False) Dict
- variable_definitions: Tuple[graphql.language.ast.VariableDefinitionNode, ...]
- class graphql.language.FieldDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- arguments: Tuple[graphql.language.ast.InputValueDefinitionNode, ...]
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives', 'arguments', 'type')
- kind: str = 'field_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.FieldNode(**kwargs: Any)
Bases:
graphql.language.ast.SelectionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- alias: Optional[graphql.language.ast.NameNode]
- arguments: Tuple[graphql.language.ast.ArgumentNode, ...]
- directives: Tuple[graphql.language.ast.DirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'directives', 'alias', 'name', 'arguments', 'selection_set')
- kind: str = 'field'
- loc: Optional[graphql.language.ast.Location]
- selection_set: Optional[graphql.language.ast.SelectionSetNode]
- to_dict(locations: bool = False) Dict
- class graphql.language.FloatValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'value')
- kind: str = 'float_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- value: str
- class graphql.language.FragmentDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.ExecutableDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.DirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives', 'variable_definitions', 'selection_set', 'type_condition')
- kind: str = 'fragment_definition'
- loc: Optional[graphql.language.ast.Location]
- selection_set: graphql.language.ast.SelectionSetNode
- to_dict(locations: bool = False) Dict
- type_condition: graphql.language.ast.NamedTypeNode
- variable_definitions: Tuple[graphql.language.ast.VariableDefinitionNode, ...]
- class graphql.language.FragmentSpreadNode(**kwargs: Any)
Bases:
graphql.language.ast.SelectionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.DirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'directives', 'name')
- kind: str = 'fragment_spread'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.InlineFragmentNode(**kwargs: Any)
Bases:
graphql.language.ast.SelectionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.DirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'directives', 'type_condition', 'selection_set')
- kind: str = 'inline_fragment'
- loc: Optional[graphql.language.ast.Location]
- selection_set: graphql.language.ast.SelectionSetNode
- to_dict(locations: bool = False) Dict
- type_condition: graphql.language.ast.NamedTypeNode
- class graphql.language.InputObjectTypeDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- fields: Tuple[graphql.language.ast.InputValueDefinitionNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives', 'fields')
- kind: str = 'input_object_type_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.InputObjectTypeExtensionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- fields: Tuple[graphql.language.ast.InputValueDefinitionNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives', 'fields')
- kind: str = 'input_object_type_extension'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.InputValueDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- default_value: Optional[Union[graphql.language.ast.IntValueNode, graphql.language.ast.FloatValueNode, graphql.language.ast.StringValueNode, graphql.language.ast.BooleanValueNode, graphql.language.ast.NullValueNode, graphql.language.ast.EnumValueNode, graphql.language.ast.ConstListValueNode, graphql.language.ast.ConstObjectValueNode]]
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives', 'type', 'default_value')
- kind: str = 'input_value_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.IntValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'value')
- kind: str = 'int_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- value: str
- class graphql.language.InterfaceTypeDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- fields: Tuple[graphql.language.ast.FieldDefinitionNode, ...]
- interfaces: Tuple[graphql.language.ast.NamedTypeNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives', 'fields', 'interfaces')
- kind: str = 'interface_type_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.InterfaceTypeExtensionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- fields: Tuple[graphql.language.ast.FieldDefinitionNode, ...]
- interfaces: Tuple[graphql.language.ast.NamedTypeNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives', 'interfaces', 'fields')
- kind: str = 'interface_type_extension'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.ListTypeNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'type')
- kind: str = 'list_type'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.ListValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'values')
- kind: str = 'list_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- values: Tuple[graphql.language.ast.ValueNode, ...]
- class graphql.language.NameNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'value')
- kind: str = 'name'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- value: str
- class graphql.language.NamedTypeNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'name')
- kind: str = 'named_type'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.NonNullTypeNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'type')
- kind: str = 'non_null_type'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.NullValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc',)
- kind: str = 'null_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.ObjectFieldNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'name', 'value')
- kind: str = 'object_field'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.ObjectTypeDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- fields: Tuple[graphql.language.ast.FieldDefinitionNode, ...]
- interfaces: Tuple[graphql.language.ast.NamedTypeNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives', 'interfaces', 'fields')
- kind: str = 'object_type_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.ObjectTypeExtensionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- fields: Tuple[graphql.language.ast.FieldDefinitionNode, ...]
- interfaces: Tuple[graphql.language.ast.NamedTypeNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives', 'interfaces', 'fields')
- kind: str = 'object_type_extension'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.ObjectValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- fields: Tuple[graphql.language.ast.ObjectFieldNode, ...]
- keys: Tuple[str, ...] = ('loc', 'fields')
- kind: str = 'object_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.OperationDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.ExecutableDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.DirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives', 'variable_definitions', 'selection_set', 'operation')
- kind: str = 'operation_definition'
- loc: Optional[graphql.language.ast.Location]
- name: Optional[graphql.language.ast.NameNode]
- operation: graphql.language.ast.OperationType
- selection_set: graphql.language.ast.SelectionSetNode
- to_dict(locations: bool = False) Dict
- variable_definitions: Tuple[graphql.language.ast.VariableDefinitionNode, ...]
- class graphql.language.OperationType(value)
Bases:
enum.Enum
An enumeration.
- MUTATION = 'mutation'
- QUERY = 'query'
- SUBSCRIPTION = 'subscription'
- class graphql.language.OperationTypeDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'operation', 'type')
- kind: str = 'operation_type_definition'
- loc: Optional[graphql.language.ast.Location]
- operation: graphql.language.ast.OperationType
- to_dict(locations: bool = False) Dict
- class graphql.language.ScalarTypeDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives')
- kind: str = 'scalar_type_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.ScalarTypeExtensionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives')
- kind: str = 'scalar_type_extension'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.SchemaDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeSystemDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'directives', 'operation_types')
- kind: str = 'schema_definition'
- loc: Optional[graphql.language.ast.Location]
- operation_types: Tuple[graphql.language.ast.OperationTypeDefinitionNode, ...]
- to_dict(locations: bool = False) Dict
- class graphql.language.SchemaExtensionNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'directives', 'operation_types')
- kind: str = 'schema_extension'
- loc: Optional[graphql.language.ast.Location]
- operation_types: Tuple[graphql.language.ast.OperationTypeDefinitionNode, ...]
- to_dict(locations: bool = False) Dict
- class graphql.language.SelectionNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.DirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'directives')
- kind: str = 'selection'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.SelectionSetNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'selections')
- kind: str = 'selection_set'
- loc: Optional[graphql.language.ast.Location]
- selections: Tuple[graphql.language.ast.SelectionNode, ...]
- to_dict(locations: bool = False) Dict
- class graphql.language.StringValueNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- block: Optional[bool]
- keys: Tuple[str, ...] = ('loc', 'value', 'block')
- kind: str = 'string_value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- value: str
- class graphql.language.TypeDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeSystemDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.DirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives')
- kind: str = 'type_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.TypeExtensionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeSystemDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives')
- kind: str = 'type_extension'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.TypeNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc',)
- kind: str = 'type'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.TypeSystemDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.DefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc',)
- kind: str = 'type_system_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- graphql.language.TypeSystemExtensionNode
alias of
Union
[graphql.language.ast.SchemaExtensionNode
,graphql.language.ast.TypeExtensionNode
]
- class graphql.language.UnionTypeDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeDefinitionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- description: Optional[graphql.language.ast.StringValueNode]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'description', 'name', 'directives', 'types')
- kind: str = 'union_type_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- types: Tuple[graphql.language.ast.NamedTypeNode, ...]
- class graphql.language.UnionTypeExtensionNode(**kwargs: Any)
Bases:
graphql.language.ast.TypeExtensionNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'name', 'directives', 'types')
- kind: str = 'union_type_extension'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- types: Tuple[graphql.language.ast.NamedTypeNode, ...]
- class graphql.language.ValueNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc',)
- kind: str = 'value'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- class graphql.language.VariableDefinitionNode(**kwargs: Any)
Bases:
graphql.language.ast.Node
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- default_value: Optional[Union[graphql.language.ast.IntValueNode, graphql.language.ast.FloatValueNode, graphql.language.ast.StringValueNode, graphql.language.ast.BooleanValueNode, graphql.language.ast.NullValueNode, graphql.language.ast.EnumValueNode, graphql.language.ast.ConstListValueNode, graphql.language.ast.ConstObjectValueNode]]
- directives: Tuple[graphql.language.ast.ConstDirectiveNode, ...]
- keys: Tuple[str, ...] = ('loc', 'variable', 'type', 'default_value', 'directives')
- kind: str = 'variable_definition'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
- variable: graphql.language.ast.VariableNode
- class graphql.language.VariableNode(**kwargs: Any)
Bases:
graphql.language.ast.ValueNode
- __init__(**kwargs: Any) None
Initialize the node with the given keyword arguments.
- keys: Tuple[str, ...] = ('loc', 'name')
- kind: str = 'variable'
- loc: Optional[graphql.language.ast.Location]
- to_dict(locations: bool = False) Dict
Directive locations are specified using the following enumeration:
- class graphql.language.DirectiveLocation(value)
Bases:
enum.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: graphql.language.ast.Node) bool
Check whether the given node represents a definition.
- graphql.language.is_executable_definition_node(node: graphql.language.ast.Node) bool
Check whether the given node represents an executable definition.
- graphql.language.is_selection_node(node: graphql.language.ast.Node) bool
Check whether the given node represents a selection.
- graphql.language.is_value_node(node: graphql.language.ast.Node) bool
Check whether the given node represents a value.
- graphql.language.is_const_value_node(node: graphql.language.ast.Node) bool
Check whether the given node represents a constant value.
- graphql.language.is_type_node(node: graphql.language.ast.Node) bool
Check whether the given node represents a type.
- graphql.language.is_type_system_definition_node(node: graphql.language.ast.Node) bool
Check whether the given node represents a type system definition.
- graphql.language.is_type_definition_node(node: graphql.language.ast.Node) bool
Check whether the given node represents a type definition.
- graphql.language.is_type_system_extension_node(node: graphql.language.ast.Node) bool
Check whether the given node represents a type system extension.
- graphql.language.is_type_extension_node(node: graphql.language.ast.Node) bool
Check whether the given node represents a type extension.
Lexer
- class graphql.language.Lexer(source: graphql.language.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.
- __init__(source: graphql.language.source.Source)
Given a Source object, initialize a Lexer for that source.
- advance() graphql.language.ast.Token
Advance the token stream to the next non-ignored token.
- create_token(kind: graphql.language.token_kind.TokenKind, start: int, end: int, value: Optional[str] = None) graphql.language.ast.Token
Create a token with line and column location information.
- lookahead() graphql.language.ast.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) graphql.language.ast.Token
Read a block string token from the source file.
- read_comment(start: int) graphql.language.ast.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) graphql.language.lexer.EscapeSequence
- read_escaped_unicode_fixed_width(position: int) graphql.language.lexer.EscapeSequence
- read_escaped_unicode_variable_width(position: int) graphql.language.lexer.EscapeSequence
- read_name(start: int) graphql.language.ast.Token
Read an alphanumeric + underscore name from the source.
- read_next_token(start: int) graphql.language.ast.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) graphql.language.ast.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) graphql.language.ast.Token
Read a single-quote string token from the source file.
- class graphql.language.TokenKind(value)
Bases:
enum.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: graphql.language.token_kind.TokenKind, start: int, end: int, line: int, column: int, value: Optional[str] = None)
Bases:
object
AST Token
Represents a range of characters represented by a lexical token within a Source.
- __init__(kind: graphql.language.token_kind.TokenKind, start: int, end: int, line: int, column: int, value: Optional[str] = None) None
- column: int
- property desc: str
A helper property to describe a token as a string for debugging
- end: int
- line: int
- next: Optional[graphql.language.ast.Token]
- prev: Optional[graphql.language.ast.Token]
- start: int
- value: Optional[str]
Location
- graphql.language.get_location(source: Source, position: int) graphql.language.location.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.location.FormattedSourceLocation
- 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: graphql.language.ast.Location) str
Render a helpful description of the location in the GraphQL Source document.
Parser
- graphql.language.parse(source: Union[graphql.language.source.Source, str], no_location: bool = False, max_tokens: Optional[int] = None, allow_legacy_fragment_variables: bool = False) graphql.language.ast.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. Setting the
no_location
parameter to False 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 using the
max_tokens
parameter.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 { ... }
- graphql.language.parse_type(source: Union[graphql.language.source.Source, str], no_location: bool = False, max_tokens: Optional[int] = None, allow_legacy_fragment_variables: bool = False) graphql.language.ast.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: Union[graphql.language.source.Source, str], no_location: bool = False, max_tokens: Optional[int] = None, allow_legacy_fragment_variables: bool = False) graphql.language.ast.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: Union[graphql.language.source.Source, str], no_location: bool = False, max_tokens: Optional[int] = None, allow_legacy_fragment_variables: bool = False) Union[graphql.language.ast.IntValueNode, graphql.language.ast.FloatValueNode, graphql.language.ast.StringValueNode, graphql.language.ast.BooleanValueNode, graphql.language.ast.NullValueNode, graphql.language.ast.EnumValueNode, graphql.language.ast.ConstListValueNode, graphql.language.ast.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: graphql.language.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: graphql.language.location.SourceLocation = SourceLocation(line=1, column=1))
Bases:
object
A representation of source input to GraphQL.
- __init__(body: str, name: str = 'GraphQL request', location_offset: graphql.language.location.SourceLocation = SourceLocation(line=1, column=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) graphql.language.location.SourceLocation
- location_offset
- name
- graphql.language.print_source_location(source: graphql.language.source.Source, source_location: graphql.language.location.SourceLocation) str
Render a helpful description of the location in the GraphQL Source document.
Visitor
- graphql.language.visit(root: graphql.language.ast.Node, visitor: graphql.language.visitor.Visitor, visitor_keys: Optional[Dict[str, Tuple[str, ...]]] = 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 defined 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, graphql.language.visitor.EnterLeaveVisitor]
- get_enter_leave_for_kind(kind: str) graphql.language.visitor.EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Optional[Callable[[...], Optional[graphql.language.visitor.VisitorActionEnum]]]
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kind
instead. Will be removed in v3.3.
- class graphql.language.ParallelVisitor(visitors: Collection[graphql.language.visitor.Visitor])
Bases:
graphql.language.visitor.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[graphql.language.visitor.Visitor])
Create a new visitor from the given list of parallel visitors.
- enter_leave_map: Dict[str, graphql.language.visitor.EnterLeaveVisitor]
- get_enter_leave_for_kind(kind: str) graphql.language.visitor.EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Optional[Callable[[...], Optional[graphql.language.visitor.VisitorActionEnum]]]
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kind
instead. Will be removed in v3.3.
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.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.