validate.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { GraphQLError } from '../error/GraphQLError';
  2. import { DocumentNode } from '../language/ast';
  3. import { GraphQLSchema } from '../type/schema';
  4. import { TypeInfo } from '../utilities/TypeInfo';
  5. import { ValidationRule, SDLValidationRule } from './ValidationContext';
  6. import Maybe from '../tsutils/Maybe';
  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. // @internal
  31. export function validateSDL(
  32. documentAST: DocumentNode,
  33. schemaToExtend?: Maybe<GraphQLSchema>,
  34. rules?: ReadonlyArray<SDLValidationRule>,
  35. ): GraphQLError[];
  36. /**
  37. * Utility function which asserts a SDL document is valid by throwing an error
  38. * if it is invalid.
  39. *
  40. * @internal
  41. */
  42. export function assertValidSDL(documentAST: DocumentNode): undefined;
  43. /**
  44. * Utility function which asserts a SDL document is valid by throwing an error
  45. * if it is invalid.
  46. *
  47. * @internal
  48. */
  49. export function assertValidSDLExtension(
  50. documentAST: DocumentNode,
  51. schema: GraphQLSchema,
  52. ): undefined;