GraphQLError.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import Maybe from '../tsutils/Maybe';
  2. import { ASTNode } from '../language/ast';
  3. import { Source } from '../language/source';
  4. import { SourceLocation, getLocation } from '../language/location';
  5. /**
  6. * A GraphQLError describes an Error found during the parse, validate, or
  7. * execute phases of performing a GraphQL operation. In addition to a message
  8. * and stack trace, it also includes information about the locations in a
  9. * GraphQL document and/or execution result that correspond to the Error.
  10. */
  11. export class GraphQLError extends Error {
  12. constructor(
  13. message: string,
  14. nodes?: ReadonlyArray<ASTNode> | ASTNode | undefined,
  15. source?: Maybe<Source>,
  16. positions?: Maybe<ReadonlyArray<number>>,
  17. path?: Maybe<ReadonlyArray<string | number>>,
  18. originalError?: Maybe<Error>,
  19. extensions?: Maybe<{ [key: string]: any }>,
  20. );
  21. /**
  22. * A message describing the Error for debugging purposes.
  23. *
  24. * Enumerable, and appears in the result of JSON.stringify().
  25. *
  26. * Note: should be treated as readonly, despite invariant usage.
  27. */
  28. message: string;
  29. /**
  30. * An array of { line, column } locations within the source GraphQL document
  31. * which correspond to this error.
  32. *
  33. * Errors during validation often contain multiple locations, for example to
  34. * point out two things with the same name. Errors during execution include a
  35. * single location, the field which produced the error.
  36. *
  37. * Enumerable, and appears in the result of JSON.stringify().
  38. */
  39. readonly locations: ReadonlyArray<SourceLocation> | undefined;
  40. /**
  41. * An array describing the JSON-path into the execution response which
  42. * corresponds to this error. Only included for errors during execution.
  43. *
  44. * Enumerable, and appears in the result of JSON.stringify().
  45. */
  46. readonly path: ReadonlyArray<string | number> | undefined;
  47. /**
  48. * An array of GraphQL AST Nodes corresponding to this error.
  49. */
  50. readonly nodes: ReadonlyArray<ASTNode> | undefined;
  51. /**
  52. * The source GraphQL document corresponding to this error.
  53. *
  54. * Note that if this Error represents more than one node, the source may not
  55. * represent nodes after the first node.
  56. */
  57. readonly source: Source | undefined;
  58. /**
  59. * An array of character offsets within the source GraphQL document
  60. * which correspond to this error.
  61. */
  62. readonly positions: ReadonlyArray<number> | undefined;
  63. /**
  64. * The original error thrown from a field resolver during execution.
  65. */
  66. readonly originalError: Maybe<Error>;
  67. /**
  68. * Extension fields to add to the formatted error.
  69. */
  70. readonly extensions: { [key: string]: any } | undefined;
  71. }
  72. /**
  73. * Prints a GraphQLError to a string, representing useful location information
  74. * about the error's position in the source.
  75. */
  76. export function printError(error: GraphQLError): string;