UNPKG

2.15 kBTypeScriptView Raw
1import type { Maybe } from '../jsutils/Maybe';
2import { GraphQLError } from '../error/GraphQLError';
3import type { DocumentNode } from '../language/ast';
4import type { GraphQLSchema } from '../type/schema';
5import { TypeInfo } from '../utilities/TypeInfo';
6import type { SDLValidationRule, ValidationRule } from './ValidationContext';
7/**
8 * Implements the "Validation" section of the spec.
9 *
10 * Validation runs synchronously, returning an array of encountered errors, or
11 * an empty array if no errors were encountered and the document is valid.
12 *
13 * A list of specific validation rules may be provided. If not provided, the
14 * default list of rules defined by the GraphQL specification will be used.
15 *
16 * Each validation rules is a function which returns a visitor
17 * (see the language/visitor API). Visitor methods are expected to return
18 * GraphQLErrors, or Arrays of GraphQLErrors when invalid.
19 *
20 * Validate will stop validation after a `maxErrors` limit has been reached.
21 * Attackers can send pathologically invalid queries to induce a DoS attack,
22 * so by default `maxErrors` set to 100 errors.
23 *
24 * Optionally a custom TypeInfo instance may be provided. If not provided, one
25 * will be created from the provided schema.
26 */
27export declare function validate(
28 schema: GraphQLSchema,
29 documentAST: DocumentNode,
30 rules?: ReadonlyArray<ValidationRule>,
31 options?: {
32 maxErrors?: number;
33 },
34 /** @deprecated will be removed in 17.0.0 */
35 typeInfo?: TypeInfo,
36): ReadonlyArray<GraphQLError>;
37/**
38 * @internal
39 */
40export declare function validateSDL(
41 documentAST: DocumentNode,
42 schemaToExtend?: Maybe<GraphQLSchema>,
43 rules?: ReadonlyArray<SDLValidationRule>,
44): ReadonlyArray<GraphQLError>;
45/**
46 * Utility function which asserts a SDL document is valid by throwing an error
47 * if it is invalid.
48 *
49 * @internal
50 */
51export declare function assertValidSDL(documentAST: DocumentNode): void;
52/**
53 * Utility function which asserts a SDL document is valid by throwing an error
54 * if it is invalid.
55 *
56 * @internal
57 */
58export declare function assertValidSDLExtension(
59 documentAST: DocumentNode,
60 schema: GraphQLSchema,
61): void;