UNPKG

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