Validation
GraphQL Validation
The graphql.validation
package fulfills the Validation phase of fulfilling a
GraphQL result.
- graphql.validation.validate(schema: graphql.type.schema.GraphQLSchema, document_ast: graphql.language.ast.DocumentNode, rules: Optional[Collection[Type[graphql.validation.rules.ASTValidationRule]]] = None, type_info: Optional[graphql.utilities.type_info.TypeInfo] = None, max_errors: Optional[int] = None) List[graphql.error.graphql_error.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.
Optionally a custom TypeInfo instance may be provided. If not provided, one will be created from the provided schema.
- class graphql.validation.ASTValidationContext(ast: graphql.language.ast.DocumentNode, on_error: Callable[[graphql.error.graphql_error.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: graphql.language.ast.DocumentNode, on_error: Callable[[graphql.error.graphql_error.GraphQLError], None]) None
- document: graphql.language.ast.DocumentNode
- get_fragment(name: str) Optional[graphql.language.ast.FragmentDefinitionNode]
- get_fragment_spreads(node: graphql.language.ast.SelectionSetNode) List[graphql.language.ast.FragmentSpreadNode]
- get_recursively_referenced_fragments(operation: graphql.language.ast.OperationDefinitionNode) List[graphql.language.ast.FragmentDefinitionNode]
- on_error(error: graphql.error.graphql_error.GraphQLError) None
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.ASTValidationRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.language.visitor.Visitor
Visitor for validation of an AST.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.SDLValidationContext(ast: graphql.language.ast.DocumentNode, schema: Optional[graphql.type.schema.GraphQLSchema], on_error: Callable[[graphql.error.graphql_error.GraphQLError], None])
Bases:
graphql.validation.validation_context.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: graphql.language.ast.DocumentNode, schema: Optional[graphql.type.schema.GraphQLSchema], on_error: Callable[[graphql.error.graphql_error.GraphQLError], None]) None
- document: graphql.language.ast.DocumentNode
- get_fragment(name: str) Optional[graphql.language.ast.FragmentDefinitionNode]
- get_fragment_spreads(node: graphql.language.ast.SelectionSetNode) List[graphql.language.ast.FragmentSpreadNode]
- get_recursively_referenced_fragments(operation: graphql.language.ast.OperationDefinitionNode) List[graphql.language.ast.FragmentDefinitionNode]
- on_error(error: graphql.error.graphql_error.GraphQLError) None
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- schema: Optional[graphql.type.schema.GraphQLSchema]
- class graphql.validation.SDLValidationRule(context: graphql.validation.validation_context.SDLValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
Visitor for validation of an SDL AST.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.SDLValidationContext) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.ValidationContext(schema: graphql.type.schema.GraphQLSchema, ast: graphql.language.ast.DocumentNode, type_info: graphql.utilities.type_info.TypeInfo, on_error: Callable[[graphql.error.graphql_error.GraphQLError], None])
Bases:
graphql.validation.validation_context.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: graphql.type.schema.GraphQLSchema, ast: graphql.language.ast.DocumentNode, type_info: graphql.utilities.type_info.TypeInfo, on_error: Callable[[graphql.error.graphql_error.GraphQLError], None]) None
- document: graphql.language.ast.DocumentNode
- get_argument() Optional[graphql.type.definition.GraphQLArgument]
- get_directive() Optional[graphql.type.directives.GraphQLDirective]
- get_enum_value() Optional[graphql.type.definition.GraphQLEnumValue]
- get_field_def() Optional[graphql.type.definition.GraphQLField]
- get_fragment(name: str) Optional[graphql.language.ast.FragmentDefinitionNode]
- get_fragment_spreads(node: graphql.language.ast.SelectionSetNode) List[graphql.language.ast.FragmentSpreadNode]
- get_input_type() Optional[Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType]]
- get_parent_input_type() Optional[Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLInputObjectType, graphql.type.definition.GraphQLWrappingType]]
- get_parent_type() Optional[Union[graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]]
- get_recursive_variable_usages(operation: graphql.language.ast.OperationDefinitionNode) List[graphql.validation.validation_context.VariableUsage]
- get_recursively_referenced_fragments(operation: graphql.language.ast.OperationDefinitionNode) List[graphql.language.ast.FragmentDefinitionNode]
- get_type() Optional[Union[graphql.type.definition.GraphQLScalarType, graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType, graphql.type.definition.GraphQLEnumType, graphql.type.definition.GraphQLWrappingType]]
- get_variable_usages(node: Union[graphql.language.ast.OperationDefinitionNode, graphql.language.ast.FragmentDefinitionNode]) List[graphql.validation.validation_context.VariableUsage]
- on_error(error: graphql.error.graphql_error.GraphQLError) None
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.ValidationRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
Visitor for validation using a GraphQL schema.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Rules
- graphql.validation.specified_rules = FrozenList([...])
This list includes all validation rules defined by the GraphQL spec.
The order of the rules in this list has been adjusted to lead to the most clear output when encountering multiple validation errors.
Spec Section: “Executable Definitions”
- class graphql.validation.ExecutableDefinitionsRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
Executable definitions
A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- enter_document(node: graphql.language.ast.DocumentNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Field Selections on Objects, Interfaces, and Unions Types”
- class graphql.validation.FieldsOnCorrectTypeRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.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
.- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext) None
- enter_field(node: graphql.language.ast.FieldNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Fragments on Composite Types”
- class graphql.validation.FragmentsOnCompositeTypesRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.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.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext) None
- enter_fragment_definition(node: graphql.language.ast.FragmentDefinitionNode, *_args: Any) None
- enter_inline_fragment(node: graphql.language.ast.InlineFragmentNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Argument Names”
- class graphql.validation.KnownArgumentNamesRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.known_argument_names.KnownArgumentNamesOnDirectivesRule
Known argument names
A GraphQL field is only valid if all supplied arguments are defined by that field.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext)
- enter_argument(arg_node: graphql.language.ast.ArgumentNode, *args: Any) None
- enter_directive(directive_node: graphql.language.ast.DirectiveNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Directives Are Defined”
- class graphql.validation.KnownDirectivesRule(context: Union[graphql.validation.validation_context.ValidationContext, graphql.validation.validation_context.SDLValidationContext])
Bases:
graphql.validation.rules.ASTValidationRule
Known directives
A GraphQL document is only valid if all
@directives
are known by the schema and legally positioned.- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: Union[graphql.validation.validation_context.ValidationContext, graphql.validation.validation_context.SDLValidationContext])
- context: Union[graphql.validation.validation_context.ValidationContext, graphql.validation.validation_context.SDLValidationContext]
- enter_directive(node: graphql.language.ast.DirectiveNode, _key: Any, _parent: Any, _path: Any, ancestors: List[graphql.language.ast.Node]) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Fragment spread target defined”
- class graphql.validation.KnownFragmentNamesRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.ValidationRule
Known fragment names
A GraphQL document is only valid if all
...Fragment
fragment spreads refer to fragments defined in the same document.- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext) None
- enter_fragment_spread(node: graphql.language.ast.FragmentSpreadNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Fragment Spread Type Existence”
- class graphql.validation.KnownTypeNamesRule(context: Union[graphql.validation.validation_context.ValidationContext, graphql.validation.validation_context.SDLValidationContext])
Bases:
graphql.validation.rules.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.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: Union[graphql.validation.validation_context.ValidationContext, graphql.validation.validation_context.SDLValidationContext])
- enter_named_type(node: graphql.language.ast.NamedTypeNode, _key: Any, parent: graphql.language.ast.Node, _path: Any, ancestors: List[graphql.language.ast.Node]) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Lone Anonymous Operation”
- class graphql.validation.LoneAnonymousOperationRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.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.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- enter_document(node: graphql.language.ast.DocumentNode, *_args: Any) None
- enter_operation_definition(node: graphql.language.ast.OperationDefinitionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Fragments must not form cycles”
- class graphql.validation.NoFragmentCyclesRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
No fragment cycles
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- detect_cycle_recursive(fragment: graphql.language.ast.FragmentDefinitionNode) None
- enter_fragment_definition(node: graphql.language.ast.FragmentDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- static enter_operation_definition(*_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “All Variable Used Defined”
- class graphql.validation.NoUndefinedVariablesRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.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.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext)
- enter_operation_definition(*_args: Any) None
- enter_variable_definition(node: graphql.language.ast.VariableDefinitionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- leave_operation_definition(operation: graphql.language.ast.OperationDefinitionNode, *_args: Any) None
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Fragments must be used”
- class graphql.validation.NoUnusedFragmentsRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.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.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- enter_fragment_definition(node: graphql.language.ast.FragmentDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_operation_definition(node: graphql.language.ast.OperationDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- leave_document(*_args: Any) None
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “All Variables Used”
- class graphql.validation.NoUnusedVariablesRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.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.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext)
- enter_operation_definition(*_args: Any) None
- enter_variable_definition(definition: graphql.language.ast.VariableDefinitionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- leave_operation_definition(operation: graphql.language.ast.OperationDefinitionNode, *_args: Any) None
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Field Selection Merging”
- class graphql.validation.OverlappingFieldsCanBeMergedRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.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.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext)
- enter_selection_set(selection_set: graphql.language.ast.SelectionSetNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Fragment spread is possible”
- class graphql.validation.PossibleFragmentSpreadsRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.ValidationContext) None
- enter_fragment_spread(node: graphql.language.ast.FragmentSpreadNode, *_args: Any) None
- enter_inline_fragment(node: graphql.language.ast.InlineFragmentNode, *_args: Any) None
- get_fragment_type(name: str) Optional[Union[graphql.type.definition.GraphQLObjectType, graphql.type.definition.GraphQLInterfaceType, graphql.type.definition.GraphQLUnionType]]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Argument Optionality”
- class graphql.validation.ProvidedRequiredArgumentsRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.provided_required_arguments.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: graphql.validation.validation_context.ValidationContext)
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- leave_directive(directive_node: graphql.language.ast.DirectiveNode, *_args: Any) None
- leave_field(field_node: graphql.language.ast.FieldNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Leaf Field Selections”
- class graphql.validation.ScalarLeafsRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.ValidationContext) None
- enter_field(node: graphql.language.ast.FieldNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Subscriptions with Single Root Field”
- class graphql.validation.SingleFieldSubscriptionsRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
Subscriptions must only include one field.
A GraphQL subscription is valid only if it contains a single root.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- enter_operation_definition(node: graphql.language.ast.OperationDefinitionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Argument Uniqueness”
- class graphql.validation.UniqueArgumentNamesRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
Unique argument names
A GraphQL field or directive is only valid if all supplied arguments are uniquely named.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- enter_argument(node: graphql.language.ast.ArgumentNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_directive(*_args: Any) None
- enter_field(*_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Directives Are Unique Per Location”
- class graphql.validation.UniqueDirectivesPerLocationRule(context: Union[graphql.validation.validation_context.ValidationContext, graphql.validation.validation_context.SDLValidationContext])
Bases:
graphql.validation.rules.ASTValidationRule
Unique directive names per location
A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: Union[graphql.validation.validation_context.ValidationContext, graphql.validation.validation_context.SDLValidationContext])
- context: Union[graphql.validation.validation_context.ValidationContext, graphql.validation.validation_context.SDLValidationContext]
- enter(node: graphql.language.ast.Node, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Fragment Name Uniqueness”
- class graphql.validation.UniqueFragmentNamesRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
Unique fragment names
A GraphQL document is only valid if all defined fragments have unique names.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- enter_fragment_definition(node: graphql.language.ast.FragmentDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- static enter_operation_definition(*_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Input Object Field Uniqueness”
- class graphql.validation.UniqueInputFieldNamesRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
Unique input field names
A GraphQL input object value is only valid if all supplied fields are uniquely named.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- enter_object_field(node: graphql.language.ast.ObjectFieldNode, *_args: Any) None
- enter_object_value(*_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- leave_object_value(*_args: Any) None
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Operation Name Uniqueness”
- class graphql.validation.UniqueOperationNamesRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.ASTValidationRule
Unique operation names
A GraphQL document is only valid if all defined operations have unique names.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ASTValidationContext)
- static enter_fragment_definition(*_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_operation_definition(node: graphql.language.ast.OperationDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Variable Uniqueness”
- class graphql.validation.UniqueVariableNamesRule(context: graphql.validation.validation_context.ASTValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.ASTValidationContext)
- enter_operation_definition(*_args: Any) None
- enter_variable_definition(node: graphql.language.ast.VariableDefinitionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Value Type Correctness”
- class graphql.validation.ValuesOfCorrectTypeRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.ValidationRule
Value literals of correct type
A GraphQL document is only valid if all value literals are of the type expected at their position.
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext) None
- enter_boolean_value(node: graphql.language.ast.BooleanValueNode, *_args: Any) None
- enter_enum_value(node: graphql.language.ast.EnumValueNode, *_args: Any) None
- enter_float_value(node: graphql.language.ast.FloatValueNode, *_args: Any) None
- enter_int_value(node: graphql.language.ast.IntValueNode, *_args: Any) None
- enter_list_value(node: graphql.language.ast.ListValueNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_null_value(node: graphql.language.ast.NullValueNode, *_args: Any) None
- enter_object_field(node: graphql.language.ast.ObjectFieldNode, *_args: Any) None
- enter_object_value(node: graphql.language.ast.ObjectValueNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_string_value(node: graphql.language.ast.StringValueNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- is_valid_value_node(node: graphql.language.ast.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: graphql.error.graphql_error.GraphQLError) None
Spec Section: “Variables are Input Types”
- class graphql.validation.VariablesAreInputTypesRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.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).
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext) None
- enter_variable_definition(node: graphql.language.ast.VariableDefinitionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
Spec Section: “All Variable Usages Are Allowed”
- class graphql.validation.VariablesInAllowedPositionRule(context: graphql.validation.validation_context.ValidationContext)
Bases:
graphql.validation.rules.ValidationRule
Variables passed to field arguments conform to type
- BREAK = True
- IDLE = None
- REMOVE = Ellipsis
- SKIP = False
- __init__(context: graphql.validation.validation_context.ValidationContext)
- enter_operation_definition(*_args: Any) None
- enter_variable_definition(node: graphql.language.ast.VariableDefinitionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- leave_operation_definition(operation: graphql.language.ast.OperationDefinitionNode, *_args: Any) None
- report_error(error: graphql.error.graphql_error.GraphQLError) None
SDL-specific validation rules
- class graphql.validation.LoneSchemaDefinitionRule(context: graphql.validation.validation_context.SDLValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.SDLValidationContext)
- enter_schema_definition(node: graphql.language.ast.SchemaDefinitionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.UniqueOperationTypesRule(context: graphql.validation.validation_context.SDLValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.SDLValidationContext)
- check_operation_types(node: Union[graphql.language.ast.SchemaDefinitionNode, graphql.language.ast.SchemaExtensionNode], *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_schema_definition(node: Union[graphql.language.ast.SchemaDefinitionNode, graphql.language.ast.SchemaExtensionNode], *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_schema_extension(node: Union[graphql.language.ast.SchemaDefinitionNode, graphql.language.ast.SchemaExtensionNode], *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.UniqueTypeNamesRule(context: graphql.validation.validation_context.SDLValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.SDLValidationContext)
- check_type_name(node: graphql.language.ast.TypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_enum_type_definition(node: graphql.language.ast.TypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_input_object_type_definition(node: graphql.language.ast.TypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_interface_type_definition(node: graphql.language.ast.TypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_object_type_definition(node: graphql.language.ast.TypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_scalar_type_definition(node: graphql.language.ast.TypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_union_type_definition(node: graphql.language.ast.TypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.UniqueEnumValueNamesRule(context: graphql.validation.validation_context.SDLValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.SDLValidationContext)
- check_value_uniqueness(node: graphql.language.ast.EnumTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_enum_type_definition(node: graphql.language.ast.EnumTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_enum_type_extension(node: graphql.language.ast.EnumTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.UniqueFieldDefinitionNamesRule(context: graphql.validation.validation_context.SDLValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.SDLValidationContext)
- check_field_uniqueness(node: graphql.language.ast.ObjectTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_input_object_type_definition(node: graphql.language.ast.ObjectTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_input_object_type_extension(node: graphql.language.ast.ObjectTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_interface_type_definition(node: graphql.language.ast.ObjectTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_interface_type_extension(node: graphql.language.ast.ObjectTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_object_type_definition(node: graphql.language.ast.ObjectTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- enter_object_type_extension(node: graphql.language.ast.ObjectTypeDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.UniqueDirectiveNamesRule(context: graphql.validation.validation_context.SDLValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.SDLValidationContext)
- enter_directive_definition(node: graphql.language.ast.DirectiveDefinitionNode, *_args: Any) Optional[graphql.language.visitor.VisitorActionEnum]
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None
- class graphql.validation.PossibleTypeExtensionsRule(context: graphql.validation.validation_context.SDLValidationContext)
Bases:
graphql.validation.rules.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: graphql.validation.validation_context.SDLValidationContext)
- check_extension(node: graphql.language.ast.TypeExtensionNode, *_args: Any) None
- enter_enum_type_extension(node: graphql.language.ast.TypeExtensionNode, *_args: Any) None
- enter_input_object_type_extension(node: graphql.language.ast.TypeExtensionNode, *_args: Any) None
- enter_interface_type_extension(node: graphql.language.ast.TypeExtensionNode, *_args: Any) None
- enter_object_type_extension(node: graphql.language.ast.TypeExtensionNode, *_args: Any) None
- enter_scalar_type_extension(node: graphql.language.ast.TypeExtensionNode, *_args: Any) None
- enter_union_type_extension(node: graphql.language.ast.TypeExtensionNode, *_args: Any) None
- get_visit_fn(kind: str, is_leaving: bool = False) Callable
Get the visit function for the given node kind and direction.
- report_error(error: graphql.error.graphql_error.GraphQLError) None