UNPKG

1.55 kBTypeScriptView Raw
1import { GraphQLError } from "../error";
2import { DocumentNode } from "../language/ast";
3import { GraphQLSchema } from "../type/schema";
4import { TypeInfo } from "../utilities/TypeInfo";
5import { ValidationRule } from "./ValidationContext";
6
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 * Optionally a custom TypeInfo instance may be provided. If not provided, one
21 * will be created from the provided schema.
22 */
23export function validate(
24 schema: GraphQLSchema,
25 documentAST: DocumentNode,
26 rules?: ReadonlyArray<ValidationRule>,
27 typeInfo?: TypeInfo
28): ReadonlyArray<GraphQLError>;
29
30/**
31 * Utility function which asserts a SDL document is valid by throwing an error
32 * if it is invalid.
33 *
34 * @internal
35 */
36export function assertValidSDL(documentAST: DocumentNode): undefined;
37
38/**
39 * Utility function which asserts a SDL document is valid by throwing an error
40 * if it is invalid.
41 *
42 * @internal
43 */
44export function assertValidSDLExtension(documentAST: DocumentNode, schema: GraphQLSchema): undefined;