Validation

GraphQL Validation

The graphql.validation package fulfills the Validation phase of fulfilling a GraphQL result.

graphql.validation.validate(schema: GraphQLSchema, document_ast: DocumentNode, rules: Collection[type[ASTValidationRule]] | None = None, max_errors: int | None = None, type_info: TypeInfo | None = None) list[GraphQLError]

Implements the “Validation” section of the spec.

Validation runs synchronously, returning a list of encountered errors, or an empty list if no errors were encountered and the document is valid.

A list of specific validation rules may be provided. If not provided, the default list of rules defined by the GraphQL specification will be used.

Each validation rule is a ValidationRule object which is a visitor object that holds a ValidationContext (see the language/visitor API). Visitor methods are expected to return GraphQLErrors, or lists of GraphQLErrors when invalid.

Validate will stop validation after a max_errors limit has been reached. Attackers can send pathologically invalid queries to induce a DoS attack, so by default max_errors set to 100 errors.

Providing a custom TypeInfo instance is deprecated and will be removed in v3.3.

class graphql.validation.ASTValidationContext(ast: DocumentNode, on_error: Callable[[GraphQLError], None])

Bases: object

Utility class providing a context for validation of an AST.

An instance of this class is passed as the context attribute to all Validators, allowing access to commonly useful contextual information from within a validation rule.

__init__(ast: DocumentNode, on_error: Callable[[GraphQLError], None]) None
document: DocumentNode
get_fragment(name: str) graphql.language.ast.FragmentDefinitionNode | None
get_fragment_spreads(node: SelectionSetNode) list[graphql.language.ast.FragmentSpreadNode]
get_recursively_referenced_fragments(operation: OperationDefinitionNode) list[graphql.language.ast.FragmentDefinitionNode]
on_error(error: GraphQLError) None
report_error(error: GraphQLError) None
class graphql.validation.ASTValidationRule(context: ASTValidationContext)

Bases: Visitor

Visitor for validation of an AST.

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

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.SDLValidationContext(ast: DocumentNode, schema: GraphQLSchema | None, on_error: Callable[[GraphQLError], None])

Bases: ASTValidationContext

Utility class providing a context for validation of an SDL AST.

An instance of this class is passed as the context attribute to all Validators, allowing access to commonly useful contextual information from within a validation rule.

__init__(ast: DocumentNode, schema: GraphQLSchema | None, on_error: Callable[[GraphQLError], None]) None
document: DocumentNode
get_fragment(name: str) graphql.language.ast.FragmentDefinitionNode | None
get_fragment_spreads(node: SelectionSetNode) list[graphql.language.ast.FragmentSpreadNode]
get_recursively_referenced_fragments(operation: OperationDefinitionNode) list[graphql.language.ast.FragmentDefinitionNode]
on_error(error: GraphQLError) None
report_error(error: GraphQLError) None
schema: GraphQLSchema | None
class graphql.validation.SDLValidationRule(context: SDLValidationContext)

Bases: ASTValidationRule

Visitor for validation of an SDL AST.

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

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.ValidationContext(schema: GraphQLSchema, ast: DocumentNode, type_info: TypeInfo, on_error: Callable[[GraphQLError], None])

Bases: ASTValidationContext

Utility class providing a context for validation using a GraphQL schema.

An instance of this class is passed as the context attribute to all Validators, allowing access to commonly useful contextual information from within a validation rule.

__init__(schema: GraphQLSchema, ast: DocumentNode, type_info: TypeInfo, on_error: Callable[[GraphQLError], None]) None
document: DocumentNode
get_argument() GraphQLArgument | None
get_directive() GraphQLDirective | None
get_enum_value() GraphQLEnumValue | None
get_field_def() GraphQLField | None
get_fragment(name: str) graphql.language.ast.FragmentDefinitionNode | None
get_fragment_spreads(node: SelectionSetNode) list[graphql.language.ast.FragmentSpreadNode]
get_input_type() GraphQLInputType | None
get_parent_input_type() GraphQLInputType | None
get_parent_type() GraphQLCompositeType | None
get_recursive_variable_usages(operation: OperationDefinitionNode) list[graphql.validation.validation_context.VariableUsage]
get_recursively_referenced_fragments(operation: OperationDefinitionNode) list[graphql.language.ast.FragmentDefinitionNode]
get_type() GraphQLOutputType | None
get_variable_usages(node: Union[OperationDefinitionNode, FragmentDefinitionNode]) list[graphql.validation.validation_context.VariableUsage]
on_error(error: GraphQLError) None
report_error(error: GraphQLError) None
schema: GraphQLSchema
class graphql.validation.ValidationRule(context: ValidationContext)

Bases: ASTValidationRule

Visitor for validation using a GraphQL schema.

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

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Rules

graphql.validation.specified_rules

A tuple with all validation rules defined by the GraphQL specification

Spec Section: “Executable Definitions”

class graphql.validation.ExecutableDefinitionsRule(context: ASTValidationContext)

Bases: ASTValidationRule

Executable definitions

A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.

See https://spec.graphql.org/draft/#sec-Executable-Definitions

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
context: ASTValidationContext
enter_document(node: DocumentNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Field Selections on Objects, Interfaces, and Unions Types”

class graphql.validation.FieldsOnCorrectTypeRule(context: ValidationContext)

Bases: ValidationRule

Fields on correct type

A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as __typename.

See https://spec.graphql.org/draft/#sec-Field-Selections

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_field(node: FieldNode, *_args: Any) 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.

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Fragments on Composite Types”

class graphql.validation.FragmentsOnCompositeTypesRule(context: ValidationContext)

Bases: ValidationRule

Fragments on composite type

Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.

See https://spec.graphql.org/draft/#sec-Fragments-On-Composite-Types

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_fragment_definition(node: FragmentDefinitionNode, *_args: Any) None
enter_inline_fragment(node: InlineFragmentNode, *_args: Any) 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.

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Argument Names”

class graphql.validation.KnownArgumentNamesRule(context: ValidationContext)

Bases: KnownArgumentNamesOnDirectivesRule

Known argument names

A GraphQL field is only valid if all supplied arguments are defined by that field.

See https://spec.graphql.org/draft/#sec-Argument-Names See https://spec.graphql.org/draft/#sec-Directives-Are-In-Valid-Locations

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_argument(arg_node: ArgumentNode, *args: Any) None
enter_directive(directive_node: DirectiveNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Directives Are Defined”

class graphql.validation.KnownDirectivesRule(context: graphql.validation.validation_context.ValidationContext | graphql.validation.validation_context.SDLValidationContext)

Bases: ASTValidationRule

Known directives

A GraphQL document is only valid if all @directives are known by the schema and legally positioned.

See https://spec.graphql.org/draft/#sec-Directives-Are-Defined

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: graphql.validation.validation_context.ValidationContext | graphql.validation.validation_context.SDLValidationContext) None
context: ValidationContext | SDLValidationContext
enter_directive(node: DirectiveNode, _key: Any, _parent: Any, _path: Any, ancestors: list[graphql.language.ast.Node]) 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.

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Fragment spread target defined”

class graphql.validation.KnownFragmentNamesRule(context: ValidationContext)

Bases: ValidationRule

Known fragment names

A GraphQL document is only valid if all ...Fragment fragment spreads refer to fragments defined in the same document.

See https://spec.graphql.org/draft/#sec-Fragment-spread-target-defined

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_fragment_spread(node: FragmentSpreadNode, *_args: Any) 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.

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Fragment Spread Type Existence”

class graphql.validation.KnownTypeNamesRule(context: graphql.validation.validation_context.ValidationContext | graphql.validation.validation_context.SDLValidationContext)

Bases: ASTValidationRule

Known type names

A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.

See https://spec.graphql.org/draft/#sec-Fragment-Spread-Type-Existence

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: graphql.validation.validation_context.ValidationContext | graphql.validation.validation_context.SDLValidationContext) None
context: ASTValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_named_type(node: NamedTypeNode, _key: Any, parent: Node, _path: Any, ancestors: list[graphql.language.ast.Node]) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Lone Anonymous Operation”

class graphql.validation.LoneAnonymousOperationRule(context: ASTValidationContext)

Bases: ASTValidationRule

Lone anonymous operation

A GraphQL document is only valid if when it contains an anonymous operation (the query short-hand) that it contains only that one operation definition.

See https://spec.graphql.org/draft/#sec-Lone-Anonymous-Operation

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
context: ASTValidationContext
enter_document(node: DocumentNode, *_args: Any) None
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_operation_definition(node: OperationDefinitionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Fragments must not form cycles”

class graphql.validation.NoFragmentCyclesRule(context: ASTValidationContext)

Bases: ASTValidationRule

No fragment cycles

The graph of fragment spreads must not form any cycles including spreading itself. Otherwise an operation could infinitely spread or infinitely execute on cycles in the underlying data.

See https://spec.graphql.org/draft/#sec-Fragment-spreads-must-not-form-cycles

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
context: ASTValidationContext
detect_cycle_recursive(fragment: FragmentDefinitionNode) None
enter_fragment_definition(node: FragmentDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
static enter_operation_definition(*_args: Any) Optional[VisitorActionEnum]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “All Variable Used Defined”

class graphql.validation.NoUndefinedVariablesRule(context: ValidationContext)

Bases: ValidationRule

No undefined variables

A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.

See https://spec.graphql.org/draft/#sec-All-Variable-Uses-Defined

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_operation_definition(*_args: Any) None
enter_variable_definition(node: VariableDefinitionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

leave_operation_definition(operation: OperationDefinitionNode, *_args: Any) None
report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Fragments must be used”

class graphql.validation.NoUnusedFragmentsRule(context: ASTValidationContext)

Bases: ASTValidationRule

No unused fragments

A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.

See https://spec.graphql.org/draft/#sec-Fragments-Must-Be-Used

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
context: ASTValidationContext
enter_fragment_definition(node: FragmentDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_operation_definition(node: OperationDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

leave_document(*_args: Any) None
report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “All Variables Used”

class graphql.validation.NoUnusedVariablesRule(context: ValidationContext)

Bases: ValidationRule

No unused variables

A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.

See https://spec.graphql.org/draft/#sec-All-Variables-Used

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_operation_definition(*_args: Any) None
enter_variable_definition(definition: VariableDefinitionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

leave_operation_definition(operation: OperationDefinitionNode, *_args: Any) None
report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Field Selection Merging”

class graphql.validation.OverlappingFieldsCanBeMergedRule(context: ValidationContext)

Bases: ValidationRule

Overlapping fields can be merged

A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.

See https://spec.graphql.org/draft/#sec-Field-Selection-Merging

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_selection_set(selection_set: SelectionSetNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Fragment spread is possible”

class graphql.validation.PossibleFragmentSpreadsRule(context: ValidationContext)

Bases: ValidationRule

Possible fragment spread

A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_fragment_spread(node: FragmentSpreadNode, *_args: Any) None
enter_inline_fragment(node: InlineFragmentNode, *_args: Any) 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.

get_fragment_type(name: str) Optional[Union[GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType]]
report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Argument Optionality”

class graphql.validation.ProvidedRequiredArgumentsRule(context: ValidationContext)

Bases: ProvidedRequiredArgumentsOnDirectivesRule

Provided required arguments

A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.

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

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

leave_directive(directive_node: DirectiveNode, *_args: Any) None
leave_field(field_node: FieldNode, *_args: Any) Optional[VisitorActionEnum]
report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Leaf Field Selections”

class graphql.validation.ScalarLeafsRule(context: ValidationContext)

Bases: ValidationRule

Scalar leafs

A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_field(node: FieldNode, *_args: Any) 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.

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Subscriptions with Single Root Field”

class graphql.validation.SingleFieldSubscriptionsRule(context: ValidationContext)

Bases: ValidationRule

Subscriptions must only include a single non-introspection field.

A GraphQL subscription is valid only if it contains a single root field and that root field is not an introspection field.

See https://spec.graphql.org/draft/#sec-Single-root-field

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_operation_definition(node: OperationDefinitionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Argument Uniqueness”

class graphql.validation.UniqueArgumentNamesRule(context: ASTValidationContext)

Bases: ASTValidationRule

Unique argument names

A GraphQL field or directive is only valid if all supplied arguments are uniquely named.

See https://spec.graphql.org/draft/#sec-Argument-Names

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
check_arg_uniqueness(argument_nodes: Collection[ArgumentNode]) None
context: ASTValidationContext
enter_directive(node: DirectiveNode, *_args: Any) None
enter_field(node: FieldNode, *_args: Any) 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.

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Directives Are Unique Per Location”

class graphql.validation.UniqueDirectivesPerLocationRule(context: graphql.validation.validation_context.ValidationContext | graphql.validation.validation_context.SDLValidationContext)

Bases: ASTValidationRule

Unique directive names per location

A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.

See https://spec.graphql.org/draft/#sec-Directives-Are-Unique-Per-Location

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: graphql.validation.validation_context.ValidationContext | graphql.validation.validation_context.SDLValidationContext) None
context: ValidationContext | SDLValidationContext
enter(node: Node, *_args: Any) 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.

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Fragment Name Uniqueness”

class graphql.validation.UniqueFragmentNamesRule(context: ASTValidationContext)

Bases: ASTValidationRule

Unique fragment names

A GraphQL document is only valid if all defined fragments have unique names.

See https://spec.graphql.org/draft/#sec-Fragment-Name-Uniqueness

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
context: ASTValidationContext
enter_fragment_definition(node: FragmentDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
static enter_operation_definition(*_args: Any) Optional[VisitorActionEnum]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Input Object Field Uniqueness”

class graphql.validation.UniqueInputFieldNamesRule(context: ASTValidationContext)

Bases: ASTValidationRule

Unique input field names

A GraphQL input object value is only valid if all supplied fields are uniquely named.

See https://spec.graphql.org/draft/#sec-Input-Object-Field-Uniqueness

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
context: ASTValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_object_field(node: ObjectFieldNode, *_args: Any) None
enter_object_value(*_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

leave_object_value(*_args: Any) None
report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Operation Name Uniqueness”

class graphql.validation.UniqueOperationNamesRule(context: ASTValidationContext)

Bases: ASTValidationRule

Unique operation names

A GraphQL document is only valid if all defined operations have unique names.

See https://spec.graphql.org/draft/#sec-Operation-Name-Uniqueness

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
context: ASTValidationContext
static enter_fragment_definition(*_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_operation_definition(node: OperationDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Variable Uniqueness”

class graphql.validation.UniqueVariableNamesRule(context: ASTValidationContext)

Bases: ASTValidationRule

Unique variable names

A GraphQL operation is only valid if all its variables are uniquely named.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ASTValidationContext) None
context: ASTValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_operation_definition(node: OperationDefinitionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Value Type Correctness”

class graphql.validation.ValuesOfCorrectTypeRule(context: ValidationContext)

Bases: ValidationRule

Value literals of correct type

A GraphQL document is only valid if all value literals are of the type expected at their position.

See https://spec.graphql.org/draft/#sec-Values-of-Correct-Type

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_boolean_value(node: BooleanValueNode, *_args: Any) None
enter_enum_value(node: EnumValueNode, *_args: Any) None
enter_float_value(node: FloatValueNode, *_args: Any) None
enter_int_value(node: IntValueNode, *_args: Any) None
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_list_value(node: ListValueNode, *_args: Any) Optional[VisitorActionEnum]
enter_null_value(node: NullValueNode, *_args: Any) None
enter_object_field(node: ObjectFieldNode, *_args: Any) None
enter_object_value(node: ObjectValueNode, *_args: Any) Optional[VisitorActionEnum]
enter_string_value(node: StringValueNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

is_valid_value_node(node: ValueNode) None

Check whether this is a valid value node.

Any value literal may be a valid representation of a Scalar, depending on that scalar type.

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “Variables are Input Types”

class graphql.validation.VariablesAreInputTypesRule(context: ValidationContext)

Bases: ValidationRule

Variables are input types

A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).

See https://spec.graphql.org/draft/#sec-Variables-Are-Input-Types

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_variable_definition(node: VariableDefinitionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

Spec Section: “All Variable Usages Are Allowed”

class graphql.validation.VariablesInAllowedPositionRule(context: ValidationContext)

Bases: ValidationRule

Variables in allowed position

Variable usages must be compatible with the arguments they are passed to.

See https://spec.graphql.org/draft/#sec-All-Variable-Usages-are-Allowed

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: ValidationContext) None
context: ValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_operation_definition(*_args: Any) None
enter_variable_definition(node: VariableDefinitionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

leave_operation_definition(operation: OperationDefinitionNode, *_args: Any) None
report_error(error: GraphQLError) None

Report a GraphQL error.

SDL-specific validation rules

class graphql.validation.LoneSchemaDefinitionRule(context: SDLValidationContext)

Bases: SDLValidationRule

Lone Schema definition

A GraphQL document is only valid if it contains only one schema definition.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: SDLValidationContext) None
context: SDLValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_schema_definition(node: SchemaDefinitionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.UniqueOperationTypesRule(context: SDLValidationContext)

Bases: SDLValidationRule

Unique operation types

A GraphQL document is only valid if it has only one type per operation.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: SDLValidationContext) None
check_operation_types(node: graphql.language.ast.SchemaDefinitionNode | graphql.language.ast.SchemaExtensionNode, *_args: Any) Optional[VisitorActionEnum]
context: SDLValidationContext
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_schema_definition(node: graphql.language.ast.SchemaDefinitionNode | graphql.language.ast.SchemaExtensionNode, *_args: Any) Optional[VisitorActionEnum]
enter_schema_extension(node: graphql.language.ast.SchemaDefinitionNode | graphql.language.ast.SchemaExtensionNode, *_args: Any) Optional[VisitorActionEnum]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.UniqueTypeNamesRule(context: SDLValidationContext)

Bases: SDLValidationRule

Unique type names

A GraphQL document is only valid if all defined types have unique names.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: SDLValidationContext) None
check_type_name(node: TypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
context: SDLValidationContext
enter_enum_type_definition(node: TypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_input_object_type_definition(node: TypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_interface_type_definition(node: TypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_object_type_definition(node: TypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_scalar_type_definition(node: TypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_union_type_definition(node: TypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.UniqueEnumValueNamesRule(context: SDLValidationContext)

Bases: SDLValidationRule

Unique enum value names

A GraphQL enum type is only valid if all its values are uniquely named.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: SDLValidationContext) None
check_value_uniqueness(node: EnumTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
context: SDLValidationContext
enter_enum_type_definition(node: EnumTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_enum_type_extension(node: EnumTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.UniqueFieldDefinitionNamesRule(context: SDLValidationContext)

Bases: SDLValidationRule

Unique field definition names

A GraphQL complex type is only valid if all its fields are uniquely named.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: SDLValidationContext) None
check_field_uniqueness(node: ObjectTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
context: SDLValidationContext
enter_input_object_type_definition(node: ObjectTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_input_object_type_extension(node: ObjectTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_interface_type_definition(node: ObjectTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_interface_type_extension(node: ObjectTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_object_type_definition(node: ObjectTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_object_type_extension(node: ObjectTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.UniqueArgumentDefinitionNamesRule(context: SDLValidationContext)

Bases: SDLValidationRule

Unique argument definition names

A GraphQL Object or Interface type is only valid if all its fields have uniquely named arguments. A GraphQL Directive is only valid if all its arguments are uniquely named.

See https://spec.graphql.org/draft/#sec-Argument-Uniqueness

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: SDLValidationContext) None
check_arg_uniqueness(parent_name: str, argument_nodes: Collection[InputValueDefinitionNode]) Optional[VisitorActionEnum]
check_arg_uniqueness_per_field(name: NameNode, fields: Collection[FieldDefinitionNode]) Optional[VisitorActionEnum]
context: SDLValidationContext
enter_directive_definition(node: DirectiveDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_interface_type_definition(node: InterfaceTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_interface_type_extension(node: InterfaceTypeExtensionNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_object_type_definition(node: ObjectTypeDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_object_type_extension(node: ObjectTypeExtensionNode, *_args: Any) Optional[VisitorActionEnum]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.UniqueDirectiveNamesRule(context: SDLValidationContext)

Bases: SDLValidationRule

Unique directive names

A GraphQL document is only valid if all defined directives have unique names.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: SDLValidationContext) None
context: SDLValidationContext
enter_directive_definition(node: DirectiveDefinitionNode, *_args: Any) Optional[VisitorActionEnum]
enter_leave_map: dict[str, EnterLeaveVisitor]
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.

class graphql.validation.PossibleTypeExtensionsRule(context: SDLValidationContext)

Bases: SDLValidationRule

Possible type extension

A type extension is only valid if the type is defined and has the same kind.

BREAK = True
IDLE = None
REMOVE = Ellipsis
SKIP = False
__init__(context: SDLValidationContext) None
check_extension(node: TypeExtensionNode, *_args: Any) None
context: SDLValidationContext
enter_enum_type_extension(node: TypeExtensionNode, *_args: Any) None
enter_input_object_type_extension(node: TypeExtensionNode, *_args: Any) None
enter_interface_type_extension(node: TypeExtensionNode, *_args: Any) None
enter_leave_map: dict[str, EnterLeaveVisitor]
enter_object_type_extension(node: TypeExtensionNode, *_args: Any) None
enter_scalar_type_extension(node: TypeExtensionNode, *_args: Any) None
enter_union_type_extension(node: TypeExtensionNode, *_args: Any) None
get_enter_leave_for_kind(kind: str) EnterLeaveVisitor

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

report_error(error: GraphQLError) None

Report a GraphQL error.