formatError.d.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { SourceLocation } from '../language/location';
  2. import { GraphQLError } from './GraphQLError';
  3. /**
  4. * Given a GraphQLError, format it according to the rules described by the
  5. * Response Format, Errors section of the GraphQL Specification.
  6. */
  7. export function formatError(error: GraphQLError): GraphQLFormattedError;
  8. /**
  9. * @see https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md#errors
  10. */
  11. export interface GraphQLFormattedError<
  12. TExtensions extends Record<string, any> = Record<string, any>
  13. > {
  14. /**
  15. * A short, human-readable summary of the problem that **SHOULD NOT** change
  16. * from occurrence to occurrence of the problem, except for purposes of
  17. * localization.
  18. */
  19. readonly message: string;
  20. /**
  21. * If an error can be associated to a particular point in the requested
  22. * GraphQL document, it should contain a list of locations.
  23. */
  24. readonly locations?: ReadonlyArray<SourceLocation>;
  25. /**
  26. * If an error can be associated to a particular field in the GraphQL result,
  27. * it _must_ contain an entry with the key `path` that details the path of
  28. * the response field which experienced the error. This allows clients to
  29. * identify whether a null result is intentional or caused by a runtime error.
  30. */
  31. readonly path?: ReadonlyArray<string | number>;
  32. /**
  33. * Reserved for implementors to extend the protocol however they see fit,
  34. * and hence there are no additional restrictions on its contents.
  35. */
  36. readonly extensions?: TExtensions;
  37. }