validate.d.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Maybe } from '../jsutils/Maybe';
  2. import { GraphQLError } from '../error/GraphQLError';
  3. import { DocumentNode } from '../language/ast';
  4. import { GraphQLSchema } from '../type/schema';
  5. import { TypeInfo } from '../utilities/TypeInfo';
  6. import { ValidationRule, SDLValidationRule } 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. * Optionally a custom TypeInfo instance may be provided. If not provided, one
  21. * will be created from the provided schema.
  22. */
  23. export function validate(
  24. schema: GraphQLSchema,
  25. documentAST: DocumentNode,
  26. rules?: ReadonlyArray<ValidationRule>,
  27. typeInfo?: TypeInfo,
  28. options?: { maxErrors?: number },
  29. ): ReadonlyArray<GraphQLError>;
  30. /**
  31. * @internal
  32. */
  33. export function validateSDL(
  34. documentAST: DocumentNode,
  35. schemaToExtend?: Maybe<GraphQLSchema>,
  36. rules?: ReadonlyArray<SDLValidationRule>,
  37. ): Array<GraphQLError>;
  38. /**
  39. * Utility function which asserts a SDL document is valid by throwing an error
  40. * if it is invalid.
  41. *
  42. * @internal
  43. */
  44. export function assertValidSDL(documentAST: DocumentNode): void;
  45. /**
  46. * Utility function which asserts a SDL document is valid by throwing an error
  47. * if it is invalid.
  48. *
  49. * @internal
  50. */
  51. export function assertValidSDLExtension(
  52. documentAST: DocumentNode,
  53. schema: GraphQLSchema,
  54. ): void;