Skip to content

Commit bbb1af5

Browse files
Change type of error extensions from anonymous Record to named interfaces (#3327)
1 parent dcf3751 commit bbb1af5

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/error/GraphQLError.d.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import { ASTNode } from '../language/ast';
44
import { Source } from '../language/source';
55
import { SourceLocation } from '../language/location';
66

7+
/**
8+
* Custom extensions
9+
*
10+
* @remarks
11+
* Use a unique identifier name for your extension, for example the name of
12+
* your library or project. Do not use a shortened identifier as this increases
13+
* the risk of conflicts. We recommend you add at most one extension field,
14+
* an object which can contain all the values you need.
15+
*/
16+
export interface GraphQLErrorExtensions {
17+
[attributeName: string]: any;
18+
}
19+
720
/**
821
* A GraphQLError describes an Error found during the parse, validate, or
922
* execute phases of performing a GraphQL operation. In addition to a message
@@ -18,7 +31,7 @@ export class GraphQLError extends Error {
1831
positions?: Maybe<ReadonlyArray<number>>,
1932
path?: Maybe<ReadonlyArray<string | number>>,
2033
originalError?: Maybe<Error>,
21-
extensions?: Maybe<{ [key: string]: any }>,
34+
extensions?: Maybe<{ [key: string]: GraphQLErrorExtensions }>,
2235
);
2336

2437
/**

src/error/index.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export { GraphQLError, printError } from './GraphQLError';
1+
export {
2+
GraphQLError,
3+
GraphQLErrorExtensions,
4+
printError,
5+
} from './GraphQLError';
26
export { syntaxError } from './syntaxError';
37
export { locatedError } from './locatedError';
48
export { formatError, GraphQLFormattedError } from './formatError';

src/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export {
364364
printError,
365365
formatError,
366366
GraphQLFormattedError,
367+
GraphQLErrorExtensions,
367368
} from './error/index';
368369

369370
// Utilities for operating on GraphQL type schema and parsed sources.

0 commit comments

Comments
 (0)