graphql/validation/validation-context
Classes
ValidationContext
Validation context passed to query validation rules.
Constructor
Creates a ValidationContext instance.
Signature:
new ValidationContext(schema: GraphQLSchema, ast: DocumentNode, typeInfo: TypeInfo, onError: (error: GraphQLError): void)
Arguments
| Name | Type | Description |
|---|---|---|
| schema | GraphQLSchema | The GraphQL schema to use. |
| ast | DocumentNode | The AST value node to inspect or convert. |
| typeInfo | TypeInfo | The type info. |
| onError | (error: GraphQLError): void | The on error. |
Returns
| Type | Description |
|---|---|
ValidationContext |
getSchema()
Returns the schema being used by this validation context.
Signature:
getSchema(): GraphQLSchema
Returns
| Type | Description |
|---|---|
GraphQLSchema | The schema being validated against. |
Example
// Given a ValidationContext instance named context:
const result = context.getSchema();
// result contains the getSchema return valuegetVariableUsages()
Returns variable usages found directly within this node.
Signature:
getVariableUsages(node: OperationDefinitionNode | FragmentDefinitionNode): readonly { node: VariableNode; type: null | undefined | GraphQLInputType; defaultValue: null | undefined | unknown; parentType: null | undefined | GraphQLInputType }[]
Arguments
| Name | Type | Description |
|---|---|---|
| node | OperationDefinitionNode | FragmentDefinitionNode | The AST node to inspect or visit. |
Returns
| Type | Description |
|---|---|
readonly { node: VariableNode; type: null | undefined | GraphQLInputType; defaultValue: null | undefined | unknown; parentType: null | undefined | GraphQLInputType }[] | Variable usages found directly within this node. |
Example
// Given a ValidationContext instance named context:
const result = context.getVariableUsages(node);
// result contains the getVariableUsages return valuegetRecursiveVariableUsages()
Returns variable usages for an operation, including variables used by referenced fragments.
Signature:
getRecursiveVariableUsages(operation: OperationDefinitionNode): readonly { node: VariableNode; type: null | undefined | GraphQLInputType; defaultValue: null | undefined | unknown; parentType: null | undefined | GraphQLInputType }[]
Arguments
| Name | Type | Description |
|---|---|---|
| operation | OperationDefinitionNode | Operation definition to inspect. |
Returns
| Type | Description |
|---|---|
readonly { node: VariableNode; type: null | undefined | GraphQLInputType; defaultValue: null | undefined | unknown; parentType: null | undefined | GraphQLInputType }[] | Variable usages reachable from the operation. |
Example
// Given a ValidationContext instance named context:
const result = context.getRecursiveVariableUsages(operation);
// result contains the getRecursiveVariableUsages return valuegetType()
Returns the current output type at this point in traversal.
Signature:
getType(): null | undefined | GraphQLOutputType
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLOutputType | The current output type, if known. |
Example
// Given a ValidationContext instance named context:
const result = context.getType();
// result contains the getType return valuegetParentType()
Returns the current parent composite type.
Signature:
getParentType(): null | undefined | GraphQLCompositeType
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLCompositeType | The current parent composite type, if known. |
Example
// Given a ValidationContext instance named context:
const result = context.getParentType();
// result contains the getParentType return valuegetInputType()
Returns the current input type at this point in traversal.
Signature:
getInputType(): null | undefined | GraphQLInputType
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLInputType | The current input type, if known. |
Example
// Given a ValidationContext instance named context:
const result = context.getInputType();
// result contains the getInputType return valuegetParentInputType()
Returns the parent input type for the current input position.
Signature:
getParentInputType(): null | undefined | GraphQLInputType
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLInputType | The parent input type, if known. |
Example
// Given a ValidationContext instance named context:
const result = context.getParentInputType();
// result contains the getParentInputType return valuegetFieldDef()
Returns the current field definition.
Signature:
getFieldDef(): null | undefined | GraphQLField<unknown, unknown>
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLField<unknown, unknown> | The current field definition, if known. |
Example
// Given a ValidationContext instance named context:
const result = context.getFieldDef();
// result contains the getFieldDef return valuegetDirective()
Returns the current directive definition.
Signature:
getDirective(): null | undefined | GraphQLDirective
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLDirective | The current directive definition, if known. |
Example
// Given a ValidationContext instance named context:
const result = context.getDirective();
// result contains the getDirective return valuegetArgument()
Returns the current argument definition.
Signature:
getArgument(): null | undefined | GraphQLArgument
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLArgument | The current argument definition, if known. |
Example
// Given a ValidationContext instance named context:
const result = context.getArgument();
// result contains the getArgument return valuegetEnumValue()
Returns the current enum value definition.
Signature:
getEnumValue(): null | undefined | GraphQLEnumValue
Returns
| Type | Description |
|---|---|
null | undefined | GraphQLEnumValue | The current enum value definition, if known. |
Example
// Given a ValidationContext instance named context:
const result = context.getEnumValue();
// result contains the getEnumValue return valueTypes
ValidationRule
Type alias. A function that creates an AST visitor for validating a GraphQL document.
type ValidationRule = (context: ValidationContext): ASTVisitor;