@@ -40,15 +40,14 @@ describe('GraphQLError', () => {
40
40
} ) ;
41
41
42
42
it ( 'enumerate only properties prescribed by the spec' , ( ) => {
43
- const e = new GraphQLError (
44
- 'msg' /* message */ ,
45
- [ fieldNode ] /* nodes */ ,
46
- source /* source */ ,
47
- [ 1 , 2 , 3 ] /* positions */ ,
48
- [ 'a' , 'b' , 'c' ] /* path */ ,
49
- new Error ( 'test' ) /* originalError */ ,
50
- { foo : 'bar' } /* extensions */ ,
51
- ) ;
43
+ const e = new GraphQLError ( 'msg' /* message */ , {
44
+ nodes : [ fieldNode ] ,
45
+ source,
46
+ positions : [ 1 , 2 , 3 ] ,
47
+ path : [ 'a' , 'b' , 'c' ] ,
48
+ originalError : new Error ( 'test' ) ,
49
+ extensions : { foo : 'bar' } ,
50
+ } ) ;
52
51
53
52
expect ( Object . keys ( e ) ) . to . deep . equal ( [
54
53
'message' ,
@@ -60,14 +59,9 @@ describe('GraphQLError', () => {
60
59
61
60
it ( 'uses the stack of an original error' , ( ) => {
62
61
const original = new Error ( 'original' ) ;
63
- const e = new GraphQLError (
64
- 'msg' ,
65
- undefined ,
66
- undefined ,
67
- undefined ,
68
- undefined ,
69
- original ,
70
- ) ;
62
+ const e = new GraphQLError ( 'msg' , {
63
+ originalError : original ,
64
+ } ) ;
71
65
72
66
expect ( e ) . to . include ( {
73
67
name : 'GraphQLError' ,
@@ -79,7 +73,7 @@ describe('GraphQLError', () => {
79
73
80
74
it ( 'creates new stack if original error has no stack' , ( ) => {
81
75
const original = new Error ( 'original' ) ;
82
- const e = new GraphQLError ( 'msg' , null , null , null , null , original ) ;
76
+ const e = new GraphQLError ( 'msg' , { originalError : original } ) ;
83
77
84
78
expect ( e ) . to . include ( {
85
79
name : 'GraphQLError' ,
@@ -90,7 +84,7 @@ describe('GraphQLError', () => {
90
84
} ) ;
91
85
92
86
it ( 'converts nodes to positions and locations' , ( ) => {
93
- const e = new GraphQLError ( 'msg' , [ fieldNode ] ) ;
87
+ const e = new GraphQLError ( 'msg' , { nodes : [ fieldNode ] } ) ;
94
88
expect ( e ) . to . deep . include ( {
95
89
source,
96
90
nodes : [ fieldNode ] ,
@@ -100,7 +94,7 @@ describe('GraphQLError', () => {
100
94
} ) ;
101
95
102
96
it ( 'converts single node to positions and locations' , ( ) => {
103
- const e = new GraphQLError ( 'msg' , fieldNode ) ; // Non-array value.
97
+ const e = new GraphQLError ( 'msg' , { nodes : fieldNode } ) ; // Non-array value.
104
98
expect ( e ) . to . deep . include ( {
105
99
source,
106
100
nodes : [ fieldNode ] ,
@@ -110,7 +104,7 @@ describe('GraphQLError', () => {
110
104
} ) ;
111
105
112
106
it ( 'converts node with loc.start === 0 to positions and locations' , ( ) => {
113
- const e = new GraphQLError ( 'msg' , operationNode ) ;
107
+ const e = new GraphQLError ( 'msg' , { nodes : operationNode } ) ;
114
108
expect ( e ) . to . deep . include ( {
115
109
source,
116
110
nodes : [ operationNode ] ,
@@ -125,7 +119,7 @@ describe('GraphQLError', () => {
125
119
loc : undefined ,
126
120
} ;
127
121
128
- const e = new GraphQLError ( 'msg' , fieldNodeNoLocation ) ;
122
+ const e = new GraphQLError ( 'msg' , { nodes : fieldNodeNoLocation } ) ;
129
123
expect ( e ) . to . deep . include ( {
130
124
nodes : [ fieldNodeNoLocation ] ,
131
125
source : undefined ,
@@ -135,7 +129,7 @@ describe('GraphQLError', () => {
135
129
} ) ;
136
130
137
131
it ( 'converts source and positions to locations' , ( ) => {
138
- const e = new GraphQLError ( 'msg' , null , source , [ 6 ] ) ;
132
+ const e = new GraphQLError ( 'msg' , { source, positions : [ 6 ] } ) ;
139
133
expect ( e ) . to . deep . include ( {
140
134
source,
141
135
nodes : undefined ,
@@ -155,47 +149,31 @@ describe('GraphQLError', () => {
155
149
}
156
150
157
151
const original = new ErrorWithExtensions ( 'original' ) ;
158
- const inheritedExtensions = new GraphQLError (
159
- 'InheritedExtensions' ,
160
- undefined ,
161
- undefined ,
162
- undefined ,
163
- undefined ,
164
- original ,
165
- undefined ,
166
- ) ;
152
+ const inheritedExtensions = new GraphQLError ( 'InheritedExtensions' , {
153
+ originalError : original ,
154
+ } ) ;
167
155
168
156
expect ( inheritedExtensions ) . to . deep . include ( {
169
157
message : 'InheritedExtensions' ,
170
158
originalError : original ,
171
159
extensions : { original : 'extensions' } ,
172
160
} ) ;
173
161
174
- const ownExtensions = new GraphQLError (
175
- 'OwnExtensions' ,
176
- undefined ,
177
- undefined ,
178
- undefined ,
179
- undefined ,
180
- original ,
181
- { own : 'extensions' } ,
182
- ) ;
162
+ const ownExtensions = new GraphQLError ( 'OwnExtensions' , {
163
+ originalError : original ,
164
+ extensions : { own : 'extensions' } ,
165
+ } ) ;
183
166
184
167
expect ( ownExtensions ) . to . deep . include ( {
185
168
message : 'OwnExtensions' ,
186
169
originalError : original ,
187
170
extensions : { own : 'extensions' } ,
188
171
} ) ;
189
172
190
- const ownEmptyExtensions = new GraphQLError (
191
- 'OwnEmptyExtensions' ,
192
- undefined ,
193
- undefined ,
194
- undefined ,
195
- undefined ,
196
- original ,
197
- { } ,
198
- ) ;
173
+ const ownEmptyExtensions = new GraphQLError ( 'OwnEmptyExtensions' , {
174
+ originalError : original ,
175
+ extensions : { } ,
176
+ } ) ;
199
177
200
178
expect ( ownEmptyExtensions ) . to . deep . include ( {
201
179
message : 'OwnEmptyExtensions' ,
@@ -214,15 +192,11 @@ describe('GraphQLError', () => {
214
192
215
193
const path = [ 'path' , 2 , 'field' ] ;
216
194
const extensions = { foo : 'bar' } ;
217
- const eFull = new GraphQLError (
218
- 'msg' ,
219
- fieldNode ,
220
- undefined ,
221
- undefined ,
195
+ const eFull = new GraphQLError ( 'msg' , {
196
+ nodes : fieldNode ,
222
197
path,
223
- undefined ,
224
198
extensions,
225
- ) ;
199
+ } ) ;
226
200
227
201
// We should try to keep order of fields stable
228
202
// Changing it wouldn't be breaking change but will fail some tests in other libraries.
@@ -260,10 +234,9 @@ describe('toString', () => {
260
234
} ) ;
261
235
262
236
it ( 'prints an error using node without location' , ( ) => {
263
- const error = new GraphQLError (
264
- 'Error attached to node without location' ,
265
- parse ( '{ foo }' , { noLocation : true } ) ,
266
- ) ;
237
+ const error = new GraphQLError ( 'Error attached to node without location' , {
238
+ nodes : parse ( '{ foo }' , { noLocation : true } ) ,
239
+ } ) ;
267
240
expect ( error . toString ( ) ) . to . equal (
268
241
'Error attached to node without location' ,
269
242
) ;
@@ -330,12 +303,7 @@ describe('toJSON', () => {
330
303
} ) ;
331
304
332
305
it ( 'includes path' , ( ) => {
333
- const error = new GraphQLError ( 'msg' , null , null , null , [
334
- 'path' ,
335
- 3 ,
336
- 'to' ,
337
- 'field' ,
338
- ] ) ;
306
+ const error = new GraphQLError ( 'msg' , { path : [ 'path' , 3 , 'to' , 'field' ] } ) ;
339
307
340
308
expect ( error . toJSON ( ) ) . to . deep . equal ( {
341
309
message : 'msg' ,
@@ -344,8 +312,8 @@ describe('toJSON', () => {
344
312
} ) ;
345
313
346
314
it ( 'includes extension fields' , ( ) => {
347
- const error = new GraphQLError ( 'msg' , null , null , null , null , null , {
348
- foo : 'bar' ,
315
+ const error = new GraphQLError ( 'msg' , {
316
+ extensions : { foo : 'bar' } ,
349
317
} ) ;
350
318
351
319
expect ( error . toJSON ( ) ) . to . deep . equal ( {
@@ -354,15 +322,16 @@ describe('toJSON', () => {
354
322
} ) ;
355
323
} ) ;
356
324
357
- it ( 'can be created with the alternative object argument' , ( ) => {
358
- const error = new GraphQLError ( 'msg' , {
359
- nodes : [ operationNode ] ,
325
+ it ( 'can be created with the legacy argument list' , ( ) => {
326
+ const error = new GraphQLError (
327
+ 'msg' ,
328
+ [ operationNode ] ,
360
329
source ,
361
- positions : [ 6 ] ,
362
- path : [ 'path' , 2 , 'a' ] ,
363
- originalError : new Error ( 'I like turtles' ) ,
364
- extensions : { hee : 'I like turtles' } ,
365
- } ) ;
330
+ [ 6 ] ,
331
+ [ 'path' , 2 , 'a' ] ,
332
+ new Error ( 'I like turtles' ) ,
333
+ { hee : 'I like turtles' } ,
334
+ ) ;
366
335
367
336
expect ( error . toJSON ( ) ) . to . deep . equal ( {
368
337
message : 'msg' ,
0 commit comments