UNPKG

3.19 kBTypeScriptView Raw
1import type { Maybe } from '../jsutils/Maybe';
2import type { GraphQLError } from '../error/GraphQLError';
3import type {
4 DocumentNode,
5 FragmentDefinitionNode,
6 FragmentSpreadNode,
7 OperationDefinitionNode,
8 SelectionSetNode,
9 VariableNode,
10} from '../language/ast';
11import type { ASTVisitor } from '../language/visitor';
12import type {
13 GraphQLArgument,
14 GraphQLCompositeType,
15 GraphQLEnumValue,
16 GraphQLField,
17 GraphQLInputType,
18 GraphQLOutputType,
19} from '../type/definition';
20import type { GraphQLDirective } from '../type/directives';
21import type { GraphQLSchema } from '../type/schema';
22import { TypeInfo } from '../utilities/TypeInfo';
23declare type NodeWithSelectionSet =
24 | OperationDefinitionNode
25 | FragmentDefinitionNode;
26interface VariableUsage {
27 readonly node: VariableNode;
28 readonly type: Maybe<GraphQLInputType>;
29 readonly defaultValue: Maybe<unknown>;
30}
31/**
32 * An instance of this class is passed as the "this" context to all validators,
33 * allowing access to commonly useful contextual information from within a
34 * validation rule.
35 */
36export declare class ASTValidationContext {
37 private _ast;
38 private _onError;
39 private _fragments;
40 private _fragmentSpreads;
41 private _recursivelyReferencedFragments;
42 constructor(ast: DocumentNode, onError: (error: GraphQLError) => void);
43 get [Symbol.toStringTag](): string;
44 reportError(error: GraphQLError): void;
45 getDocument(): DocumentNode;
46 getFragment(name: string): Maybe<FragmentDefinitionNode>;
47 getFragmentSpreads(node: SelectionSetNode): ReadonlyArray<FragmentSpreadNode>;
48 getRecursivelyReferencedFragments(
49 operation: OperationDefinitionNode,
50 ): ReadonlyArray<FragmentDefinitionNode>;
51}
52export declare type ASTValidationRule = (
53 context: ASTValidationContext,
54) => ASTVisitor;
55export declare class SDLValidationContext extends ASTValidationContext {
56 private _schema;
57 constructor(
58 ast: DocumentNode,
59 schema: Maybe<GraphQLSchema>,
60 onError: (error: GraphQLError) => void,
61 );
62 get [Symbol.toStringTag](): string;
63 getSchema(): Maybe<GraphQLSchema>;
64}
65export declare type SDLValidationRule = (
66 context: SDLValidationContext,
67) => ASTVisitor;
68export declare class ValidationContext extends ASTValidationContext {
69 private _schema;
70 private _typeInfo;
71 private _variableUsages;
72 private _recursiveVariableUsages;
73 constructor(
74 schema: GraphQLSchema,
75 ast: DocumentNode,
76 typeInfo: TypeInfo,
77 onError: (error: GraphQLError) => void,
78 );
79 get [Symbol.toStringTag](): string;
80 getSchema(): GraphQLSchema;
81 getVariableUsages(node: NodeWithSelectionSet): ReadonlyArray<VariableUsage>;
82 getRecursiveVariableUsages(
83 operation: OperationDefinitionNode,
84 ): ReadonlyArray<VariableUsage>;
85 getType(): Maybe<GraphQLOutputType>;
86 getParentType(): Maybe<GraphQLCompositeType>;
87 getInputType(): Maybe<GraphQLInputType>;
88 getParentInputType(): Maybe<GraphQLInputType>;
89 getFieldDef(): Maybe<GraphQLField<unknown, unknown>>;
90 getDirective(): Maybe<GraphQLDirective>;
91 getArgument(): Maybe<GraphQLArgument>;
92 getEnumValue(): Maybe<GraphQLEnumValue>;
93}
94export declare type ValidationRule = (context: ValidationContext) => ASTVisitor;
95export {};