UNPKG

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