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_errorslimit has been reached. Attackers can send pathologically invalid queries to induce a DoS attack, so by defaultmax_errorsset 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:
objectUtility 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) FragmentDefinitionNode | None
- get_fragment_spreads(node: SelectionSetNode) List[FragmentSpreadNode]
- get_recursively_referenced_fragments(operation: OperationDefinitionNode) List[FragmentDefinitionNode]
- on_error(error: GraphQLError) None
- report_error(error: GraphQLError) None
- class graphql.validation.ASTValidationRule(context: ASTValidationContext)
Bases:
VisitorVisitor for validation of an AST.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: ASTValidationContext)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.SDLValidationContext(ast: DocumentNode, schema: GraphQLSchema | None, on_error: Callable[[GraphQLError], None])
Bases:
ASTValidationContextUtility 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) FragmentDefinitionNode | None
- get_fragment_spreads(node: SelectionSetNode) List[FragmentSpreadNode]
- get_recursively_referenced_fragments(operation: OperationDefinitionNode) List[FragmentDefinitionNode]
- on_error(error: GraphQLError) None
- report_error(error: GraphQLError) None
- schema: GraphQLSchema | None
- class graphql.validation.SDLValidationRule(context: SDLValidationContext)
Bases:
ASTValidationRuleVisitor 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.ValidationContext(schema: GraphQLSchema, ast: DocumentNode, type_info: TypeInfo, on_error: Callable[[GraphQLError], None])
Bases:
ASTValidationContextUtility 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) FragmentDefinitionNode | None
- get_fragment_spreads(node: SelectionSetNode) List[FragmentSpreadNode]
- get_input_type() GraphQLScalarType | GraphQLEnumType | GraphQLInputObjectType | GraphQLWrappingType | None
- get_parent_input_type() GraphQLScalarType | GraphQLEnumType | GraphQLInputObjectType | GraphQLWrappingType | None
- get_parent_type() GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | None
- get_recursive_variable_usages(operation: OperationDefinitionNode) List[VariableUsage]
- get_recursively_referenced_fragments(operation: OperationDefinitionNode) List[FragmentDefinitionNode]
- get_type() GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType | GraphQLWrappingType | None
- get_variable_usages(node: OperationDefinitionNode | FragmentDefinitionNode) List[VariableUsage]
- on_error(error: GraphQLError) None
- report_error(error: GraphQLError) None
- schema: GraphQLSchema
- class graphql.validation.ValidationRule(context: ValidationContext)
Bases:
ASTValidationRuleVisitor 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
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:
ASTValidationRuleExecutable 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)
- context: ASTValidationContext
- enter_document(node: DocumentNode, *_args: Any) VisitorActionEnum | 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_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Field Selections on Objects, Interfaces, and Unions Types”
- class graphql.validation.FieldsOnCorrectTypeRule(context: ValidationContext)
Bases:
ValidationRuleFields 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_leave_map: Dict[str, EnterLeaveVisitor]
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Fragments on Composite Types”
- class graphql.validation.FragmentsOnCompositeTypesRule(context: ValidationContext)
Bases:
ValidationRuleFragments 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Argument Names”
- class graphql.validation.KnownArgumentNamesRule(context: ValidationContext)
Bases:
KnownArgumentNamesOnDirectivesRuleKnown 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)
- context: ValidationContext
- enter_argument(arg_node: ArgumentNode, *args: Any) None
- enter_directive(directive_node: DirectiveNode, *_args: Any) VisitorActionEnum | 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_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Directives Are Defined”
- class graphql.validation.KnownDirectivesRule(context: ValidationContext | SDLValidationContext)
Bases:
ASTValidationRuleKnown directives
A GraphQL document is only valid if all
@directivesare 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: ValidationContext | SDLValidationContext)
- context: ValidationContext | SDLValidationContext
- enter_directive(node: DirectiveNode, _key: Any, _parent: Any, _path: Any, ancestors: List[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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Fragment spread target defined”
- class graphql.validation.KnownFragmentNamesRule(context: ValidationContext)
Bases:
ValidationRuleKnown fragment names
A GraphQL document is only valid if all
...Fragmentfragment 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Fragment Spread Type Existence”
- class graphql.validation.KnownTypeNamesRule(context: ValidationContext | SDLValidationContext)
Bases:
ASTValidationRuleKnown 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: ValidationContext | SDLValidationContext)
- context: ASTValidationContext
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- enter_named_type(node: NamedTypeNode, _key: Any, parent: Node, _path: Any, ancestors: List[Node]) None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Lone Anonymous Operation”
- class graphql.validation.LoneAnonymousOperationRule(context: ASTValidationContext)
Bases:
ASTValidationRuleLone 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Fragments must not form cycles”
- class graphql.validation.NoFragmentCyclesRule(context: ASTValidationContext)
Bases:
ASTValidationRuleNo 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)
- context: ASTValidationContext
- detect_cycle_recursive(fragment: FragmentDefinitionNode) None
- enter_fragment_definition(node: FragmentDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- static enter_operation_definition(*_args: Any) VisitorActionEnum | None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “All Variable Used Defined”
- class graphql.validation.NoUndefinedVariablesRule(context: ValidationContext)
Bases:
ValidationRuleNo 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- leave_operation_definition(operation: OperationDefinitionNode, *_args: Any) None
- report_error(error: GraphQLError) None
Spec Section: “Fragments must be used”
- class graphql.validation.NoUnusedFragmentsRule(context: ASTValidationContext)
Bases:
ASTValidationRuleNo 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)
- context: ASTValidationContext
- enter_fragment_definition(node: FragmentDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- enter_operation_definition(node: OperationDefinitionNode, *_args: Any) VisitorActionEnum | None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- leave_document(*_args: Any) None
- report_error(error: GraphQLError) None
Spec Section: “All Variables Used”
- class graphql.validation.NoUnusedVariablesRule(context: ValidationContext)
Bases:
ValidationRuleNo 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- leave_operation_definition(operation: OperationDefinitionNode, *_args: Any) None
- report_error(error: GraphQLError) None
Spec Section: “Field Selection Merging”
- class graphql.validation.OverlappingFieldsCanBeMergedRule(context: ValidationContext)
Bases:
ValidationRuleOverlapping 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Fragment spread is possible”
- class graphql.validation.PossibleFragmentSpreadsRule(context: ValidationContext)
Bases:
ValidationRulePossible 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) GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Argument Optionality”
- class graphql.validation.ProvidedRequiredArgumentsRule(context: ValidationContext)
Bases:
ProvidedRequiredArgumentsOnDirectivesRuleProvided 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- leave_directive(directive_node: DirectiveNode, *_args: Any) None
- leave_field(field_node: FieldNode, *_args: Any) VisitorActionEnum | None
- report_error(error: GraphQLError) None
Spec Section: “Leaf Field Selections”
- class graphql.validation.ScalarLeafsRule(context: ValidationContext)
Bases:
ValidationRuleScalar 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_leave_map: Dict[str, EnterLeaveVisitor]
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Subscriptions with Single Root Field”
- class graphql.validation.SingleFieldSubscriptionsRule(context: ValidationContext)
Bases:
ValidationRuleSubscriptions 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Argument Uniqueness”
- class graphql.validation.UniqueArgumentNamesRule(context: ASTValidationContext)
Bases:
ASTValidationRuleUnique 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)
- check_arg_uniqueness(argument_nodes: Collection[ArgumentNode]) None
- context: ASTValidationContext
- enter_directive(node: DirectiveNode, *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_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Directives Are Unique Per Location”
- class graphql.validation.UniqueDirectivesPerLocationRule(context: ValidationContext | SDLValidationContext)
Bases:
ASTValidationRuleUnique 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: ValidationContext | SDLValidationContext)
- context: ValidationContext | 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Fragment Name Uniqueness”
- class graphql.validation.UniqueFragmentNamesRule(context: ASTValidationContext)
Bases:
ASTValidationRuleUnique 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)
- context: ASTValidationContext
- enter_fragment_definition(node: FragmentDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- static enter_operation_definition(*_args: Any) VisitorActionEnum | None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Input Object Field Uniqueness”
- class graphql.validation.UniqueInputFieldNamesRule(context: ASTValidationContext)
Bases:
ASTValidationRuleUnique 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- leave_object_value(*_args: Any) None
- report_error(error: GraphQLError) None
Spec Section: “Operation Name Uniqueness”
- class graphql.validation.UniqueOperationNamesRule(context: ASTValidationContext)
Bases:
ASTValidationRuleUnique 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)
- context: ASTValidationContext
- static enter_fragment_definition(*_args: Any) VisitorActionEnum | None
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- enter_operation_definition(node: OperationDefinitionNode, *_args: Any) VisitorActionEnum | None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Variable Uniqueness”
- class graphql.validation.UniqueVariableNamesRule(context: ASTValidationContext)
Bases:
ASTValidationRuleUnique 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “Value Type Correctness”
- class graphql.validation.ValuesOfCorrectTypeRule(context: ValidationContext)
Bases:
ValidationRuleValue 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) VisitorActionEnum | None
- enter_null_value(node: NullValueNode, *_args: Any) None
- enter_object_field(node: ObjectFieldNode, *_args: Any) None
- enter_object_value(node: ObjectValueNode, *_args: Any) VisitorActionEnum | None
- enter_operation_definition(*_args: Any) None
- enter_string_value(node: StringValueNode, *_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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- 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
Spec Section: “Variables are Input Types”
- class graphql.validation.VariablesAreInputTypesRule(context: ValidationContext)
Bases:
ValidationRuleVariables 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
Spec Section: “All Variable Usages Are Allowed”
- class graphql.validation.VariablesInAllowedPositionRule(context: ValidationContext)
Bases:
ValidationRuleVariables 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- leave_operation_definition(operation: OperationDefinitionNode, *_args: Any) None
- report_error(error: GraphQLError) None
No spec section: “Maximum introspection depth”
- class graphql.validation.MaxIntrospectionDepthRule(context: ValidationContext)
Bases:
ASTValidationRuleChecks maximum introspection depth
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: ValidationContext) None
- context: ASTValidationContext
- enter_field(node: FieldNode, *_args: Any) VisitorActionEnum | 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_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
SDL-specific validation rules
- class graphql.validation.LoneSchemaDefinitionRule(context: SDLValidationContext)
Bases:
SDLValidationRuleLone 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.UniqueOperationTypesRule(context: SDLValidationContext)
Bases:
SDLValidationRuleUnique 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)
- check_operation_types(node: SchemaDefinitionNode | SchemaExtensionNode, *_args: Any) VisitorActionEnum | None
- context: SDLValidationContext
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- enter_schema_definition(node: SchemaDefinitionNode | SchemaExtensionNode, *_args: Any) VisitorActionEnum | None
- enter_schema_extension(node: SchemaDefinitionNode | SchemaExtensionNode, *_args: Any) VisitorActionEnum | None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.UniqueTypeNamesRule(context: SDLValidationContext)
Bases:
SDLValidationRuleUnique 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)
- check_type_name(node: TypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- context: SDLValidationContext
- enter_enum_type_definition(node: TypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_input_object_type_definition(node: TypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_interface_type_definition(node: TypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- enter_object_type_definition(node: TypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_scalar_type_definition(node: TypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_union_type_definition(node: TypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.UniqueEnumValueNamesRule(context: SDLValidationContext)
Bases:
SDLValidationRuleUnique 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)
- check_value_uniqueness(node: EnumTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- context: SDLValidationContext
- enter_enum_type_definition(node: EnumTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_enum_type_extension(node: EnumTypeDefinitionNode, *_args: Any) VisitorActionEnum | 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_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.UniqueFieldDefinitionNamesRule(context: SDLValidationContext)
Bases:
SDLValidationRuleUnique 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)
- check_field_uniqueness(node: ObjectTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- context: SDLValidationContext
- enter_input_object_type_definition(node: ObjectTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_input_object_type_extension(node: ObjectTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_interface_type_definition(node: ObjectTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_interface_type_extension(node: ObjectTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- enter_object_type_definition(node: ObjectTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_object_type_extension(node: ObjectTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.UniqueArgumentDefinitionNamesRule(context: SDLValidationContext)
Bases:
SDLValidationRuleUnique 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]) VisitorActionEnum | None
- check_arg_uniqueness_per_field(name: NameNode, fields: Collection[FieldDefinitionNode]) VisitorActionEnum | None
- context: SDLValidationContext
- enter_directive_definition(node: DirectiveDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_interface_type_definition(node: InterfaceTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_interface_type_extension(node: InterfaceTypeExtensionNode, *_args: Any) VisitorActionEnum | None
- enter_leave_map: Dict[str, EnterLeaveVisitor]
- enter_object_type_definition(node: ObjectTypeDefinitionNode, *_args: Any) VisitorActionEnum | None
- enter_object_type_extension(node: ObjectTypeExtensionNode, *_args: Any) VisitorActionEnum | None
- get_enter_leave_for_kind(kind: str) EnterLeaveVisitor
Given a node kind, return the EnterLeaveVisitor for that kind.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.UniqueDirectiveNamesRule(context: SDLValidationContext)
Bases:
SDLValidationRuleUnique 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)
- context: SDLValidationContext
- enter_directive_definition(node: DirectiveDefinitionNode, *_args: Any) VisitorActionEnum | 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_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None
- class graphql.validation.PossibleTypeExtensionsRule(context: SDLValidationContext)
Bases:
SDLValidationRulePossible 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)
- 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.
- get_visit_fn(kind: str, is_leaving: bool = False) Callable[[...], VisitorActionEnum | None] | None
Get the visit function for the given node kind and direction.
Deprecated since version 3.2: Please use
get_enter_leave_for_kindinstead. Will be removed in v3.3.
- report_error(error: GraphQLError) None