@@ -20,6 +20,41 @@ export interface GraphQLErrorExtensions {
20
20
[ attributeName : string ] : unknown ;
21
21
}
22
22
23
+ export interface GraphQLErrorArgs {
24
+ nodes ?: ReadonlyArray < ASTNode > | ASTNode | null ;
25
+ source ?: Maybe < Source > ;
26
+ positions ?: Maybe < ReadonlyArray < number > > ;
27
+ path ?: Maybe < ReadonlyArray < string | number > > ;
28
+ originalError ?: Maybe < Error & { readonly extensions ?: unknown } > ;
29
+ extensions ?: Maybe < GraphQLErrorExtensions > ;
30
+ }
31
+
32
+ type BackwardsCompatibleArgs =
33
+ | [ args ?: GraphQLErrorArgs ]
34
+ | [
35
+ nodes ?: GraphQLErrorArgs [ 'nodes' ] ,
36
+ source ?: GraphQLErrorArgs [ 'source' ] ,
37
+ positions ?: GraphQLErrorArgs [ 'positions' ] ,
38
+ path ?: GraphQLErrorArgs [ 'path' ] ,
39
+ originalError ?: GraphQLErrorArgs [ 'originalError' ] ,
40
+ extensions ?: GraphQLErrorArgs [ 'extensions' ] ,
41
+ ] ;
42
+
43
+ function toNormalizedArgs ( args : BackwardsCompatibleArgs ) : GraphQLErrorArgs {
44
+ const firstArg = args [ 0 ] ;
45
+ if ( firstArg == null || 'kind' in firstArg || 'length' in firstArg ) {
46
+ return {
47
+ nodes : firstArg ,
48
+ source : args [ 1 ] ,
49
+ positions : args [ 2 ] ,
50
+ path : args [ 3 ] ,
51
+ originalError : args [ 4 ] ,
52
+ extensions : args [ 5 ] ,
53
+ } ;
54
+ }
55
+ return firstArg ;
56
+ }
57
+
23
58
/**
24
59
* A GraphQLError describes an Error found during the parse, validate, or
25
60
* execute phases of performing a GraphQL operation. In addition to a message
@@ -76,6 +111,9 @@ export class GraphQLError extends Error {
76
111
*/
77
112
readonly extensions : GraphQLErrorExtensions ;
78
113
114
+ /**
115
+ * @deprecated Please use the `GraphQLErrorArgs` constructor overload instead.
116
+ */
79
117
constructor (
80
118
message : string ,
81
119
nodes ?: ReadonlyArray < ASTNode > | ASTNode | null ,
@@ -84,7 +122,11 @@ export class GraphQLError extends Error {
84
122
path ?: Maybe < ReadonlyArray < string | number > > ,
85
123
originalError ?: Maybe < Error & { readonly extensions ?: unknown } > ,
86
124
extensions ?: Maybe < GraphQLErrorExtensions > ,
87
- ) {
125
+ ) ;
126
+ constructor ( message : string , args ?: GraphQLErrorArgs ) ;
127
+ constructor ( message : string , ...rawArgs : BackwardsCompatibleArgs ) {
128
+ const { nodes, source, positions, path, originalError, extensions } =
129
+ toNormalizedArgs ( rawArgs ) ;
88
130
super ( message ) ;
89
131
90
132
this . name = 'GraphQLError' ;
0 commit comments