validate.d.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type { Maybe } from '../jsutils/Maybe';
  2. import { GraphQLError } from '../error/GraphQLError';
  3. import type { DocumentNode } from '../language/ast';
  4. import type { GraphQLSchema } from '../type/schema';
  5. import { TypeInfo } from '../utilities/TypeInfo';
  6. import 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. */
  27. export 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. */
  40. export 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. */
  51. export 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. */
  58. export declare function assertValidSDLExtension(
  59. documentAST: DocumentNode,
  60. schema: GraphQLSchema,
  61. ): void;