GraphQLError.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import type { Maybe } from '../jsutils/Maybe';
  2. import type { ASTNode } from '../language/ast';
  3. import type { SourceLocation } from '../language/location';
  4. import type { Source } from '../language/source';
  5. /**
  6. * Custom extensions
  7. *
  8. * @remarks
  9. * Use a unique identifier name for your extension, for example the name of
  10. * your library or project. Do not use a shortened identifier as this increases
  11. * the risk of conflicts. We recommend you add at most one extension field,
  12. * an object which can contain all the values you need.
  13. */
  14. export interface GraphQLErrorExtensions {
  15. [attributeName: string]: unknown;
  16. }
  17. export interface GraphQLErrorOptions {
  18. nodes?: ReadonlyArray<ASTNode> | ASTNode | null;
  19. source?: Maybe<Source>;
  20. positions?: Maybe<ReadonlyArray<number>>;
  21. path?: Maybe<ReadonlyArray<string | number>>;
  22. originalError?: Maybe<
  23. Error & {
  24. readonly extensions?: unknown;
  25. }
  26. >;
  27. extensions?: Maybe<GraphQLErrorExtensions>;
  28. }
  29. /**
  30. * A GraphQLError describes an Error found during the parse, validate, or
  31. * execute phases of performing a GraphQL operation. In addition to a message
  32. * and stack trace, it also includes information about the locations in a
  33. * GraphQL document and/or execution result that correspond to the Error.
  34. */
  35. export declare class GraphQLError extends Error {
  36. /**
  37. * An array of `{ line, column }` locations within the source GraphQL document
  38. * which correspond to this error.
  39. *
  40. * Errors during validation often contain multiple locations, for example to
  41. * point out two things with the same name. Errors during execution include a
  42. * single location, the field which produced the error.
  43. *
  44. * Enumerable, and appears in the result of JSON.stringify().
  45. */
  46. readonly locations: ReadonlyArray<SourceLocation> | undefined;
  47. /**
  48. * An array describing the JSON-path into the execution response which
  49. * corresponds to this error. Only included for errors during execution.
  50. *
  51. * Enumerable, and appears in the result of JSON.stringify().
  52. */
  53. readonly path: ReadonlyArray<string | number> | undefined;
  54. /**
  55. * An array of GraphQL AST Nodes corresponding to this error.
  56. */
  57. readonly nodes: ReadonlyArray<ASTNode> | undefined;
  58. /**
  59. * The source GraphQL document for the first location of this error.
  60. *
  61. * Note that if this Error represents more than one node, the source may not
  62. * represent nodes after the first node.
  63. */
  64. readonly source: Source | undefined;
  65. /**
  66. * An array of character offsets within the source GraphQL document
  67. * which correspond to this error.
  68. */
  69. readonly positions: ReadonlyArray<number> | undefined;
  70. /**
  71. * The original error thrown from a field resolver during execution.
  72. */
  73. readonly originalError: Error | undefined;
  74. /**
  75. * Extension fields to add to the formatted error.
  76. */
  77. readonly extensions: GraphQLErrorExtensions;
  78. constructor(message: string, options?: GraphQLErrorOptions);
  79. /**
  80. * @deprecated Please use the `GraphQLErrorOptions` constructor overload instead.
  81. */
  82. constructor(
  83. message: string,
  84. nodes?: ReadonlyArray<ASTNode> | ASTNode | null,
  85. source?: Maybe<Source>,
  86. positions?: Maybe<ReadonlyArray<number>>,
  87. path?: Maybe<ReadonlyArray<string | number>>,
  88. originalError?: Maybe<
  89. Error & {
  90. readonly extensions?: unknown;
  91. }
  92. >,
  93. extensions?: Maybe<GraphQLErrorExtensions>,
  94. );
  95. get [Symbol.toStringTag](): string;
  96. toString(): string;
  97. toJSON(): GraphQLFormattedError;
  98. }
  99. /**
  100. * See: https://spec.graphql.org/draft/#sec-Errors
  101. */
  102. export interface GraphQLFormattedError {
  103. /**
  104. * A short, human-readable summary of the problem that **SHOULD NOT** change
  105. * from occurrence to occurrence of the problem, except for purposes of
  106. * localization.
  107. */
  108. readonly message: string;
  109. /**
  110. * If an error can be associated to a particular point in the requested
  111. * GraphQL document, it should contain a list of locations.
  112. */
  113. readonly locations?: ReadonlyArray<SourceLocation>;
  114. /**
  115. * If an error can be associated to a particular field in the GraphQL result,
  116. * it _must_ contain an entry with the key `path` that details the path of
  117. * the response field which experienced the error. This allows clients to
  118. * identify whether a null result is intentional or caused by a runtime error.
  119. */
  120. readonly path?: ReadonlyArray<string | number>;
  121. /**
  122. * Reserved for implementors to extend the protocol however they see fit,
  123. * and hence there are no additional restrictions on its contents.
  124. */
  125. readonly extensions?: {
  126. [key: string]: unknown;
  127. };
  128. }
  129. /**
  130. * Prints a GraphQLError to a string, representing useful location information
  131. * about the error's position in the source.
  132. *
  133. * @deprecated Please use `error.toString` instead. Will be removed in v17
  134. */
  135. export declare function printError(error: GraphQLError): string;
  136. /**
  137. * Given a GraphQLError, format it according to the rules described by the
  138. * Response Format, Errors section of the GraphQL Specification.
  139. *
  140. * @deprecated Please use `error.toJSON` instead. Will be removed in v17
  141. */
  142. export declare function formatError(error: GraphQLError): GraphQLFormattedError;