1 | import Maybe from '../tsutils/Maybe';
|
2 | import { GraphQLError } from '../error/GraphQLError';
|
3 | import { ASTVisitor } from '../language/visitor';
|
4 | import {
|
5 | DocumentNode,
|
6 | OperationDefinitionNode,
|
7 | VariableNode,
|
8 | SelectionSetNode,
|
9 | FragmentSpreadNode,
|
10 | FragmentDefinitionNode,
|
11 | } from '../language/ast';
|
12 | import { GraphQLSchema } from '../type/schema';
|
13 | import { GraphQLDirective } from '../type/directives';
|
14 | import {
|
15 | GraphQLInputType,
|
16 | GraphQLOutputType,
|
17 | GraphQLCompositeType,
|
18 | GraphQLField,
|
19 | GraphQLArgument,
|
20 | } from '../type/definition';
|
21 | import { TypeInfo } from '../utilities/TypeInfo';
|
22 |
|
23 | type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode;
|
24 | type VariableUsage = {
|
25 | readonly node: VariableNode;
|
26 | readonly type: Maybe<GraphQLInputType>;
|
27 | readonly defaultValue: Maybe<any>;
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | export class ASTValidationContext {
|
36 | constructor(ast: DocumentNode);
|
37 |
|
38 | reportError(error: GraphQLError): undefined;
|
39 |
|
40 | getErrors(): ReadonlyArray<GraphQLError>;
|
41 |
|
42 | getDocument(): DocumentNode;
|
43 |
|
44 | getFragment(name: string): Maybe<FragmentDefinitionNode>;
|
45 |
|
46 | getFragmentSpreads(node: SelectionSetNode): ReadonlyArray<FragmentSpreadNode>;
|
47 |
|
48 | getRecursivelyReferencedFragments(
|
49 | operation: OperationDefinitionNode,
|
50 | ): ReadonlyArray<FragmentDefinitionNode>;
|
51 | }
|
52 |
|
53 | export class SDLValidationContext extends ASTValidationContext {
|
54 | constructor(
|
55 | ast: DocumentNode,
|
56 | schema: Maybe<GraphQLSchema>,
|
57 | onError?: (err: GraphQLError) => void,
|
58 | );
|
59 |
|
60 | getSchema(): Maybe<GraphQLSchema>;
|
61 | }
|
62 |
|
63 | export type SDLValidationRule = (context: SDLValidationContext) => ASTVisitor;
|
64 |
|
65 | export class ValidationContext extends ASTValidationContext {
|
66 | constructor(
|
67 | schema: GraphQLSchema,
|
68 | ast: DocumentNode,
|
69 | typeInfo: TypeInfo,
|
70 | onError?: (err: GraphQLError) => void,
|
71 | );
|
72 |
|
73 | getSchema(): GraphQLSchema;
|
74 |
|
75 | getVariableUsages(node: NodeWithSelectionSet): ReadonlyArray<VariableUsage>;
|
76 |
|
77 | getRecursivelyReferencedFragments(
|
78 | operation: OperationDefinitionNode,
|
79 | ): ReadonlyArray<FragmentDefinitionNode>;
|
80 |
|
81 | getType(): Maybe<GraphQLOutputType>;
|
82 |
|
83 | getParentType(): Maybe<GraphQLCompositeType>;
|
84 |
|
85 | getInputType(): Maybe<GraphQLInputType>;
|
86 |
|
87 | getParentInputType(): Maybe<GraphQLInputType>;
|
88 |
|
89 | getFieldDef(): Maybe<GraphQLField<any, any>>;
|
90 |
|
91 | getDirective(): Maybe<GraphQLDirective>;
|
92 |
|
93 | getArgument(): Maybe<GraphQLArgument>;
|
94 | }
|
95 |
|
96 | export type ValidationRule = (context: ValidationContext) => ASTVisitor;
|