@@ -89,7 +89,104 @@ describe('Execute: Cancellation', () => {
89
89
} ,
90
90
} ) ;
91
91
92
- abortController . abort ( 'Aborted' ) ;
92
+ abortController . abort ( ) ;
93
+
94
+ const result = await resultPromise ;
95
+
96
+ expect ( result . errors ?. [ 0 ] . originalError ?. name ) . to . equal ( 'AbortError' ) ;
97
+
98
+ expectJSON ( result ) . toDeepEqual ( {
99
+ data : {
100
+ todo : null ,
101
+ } ,
102
+ errors : [
103
+ {
104
+ message : 'This operation was aborted' ,
105
+ path : [ 'todo' ] ,
106
+ locations : [ { line : 3 , column : 9 } ] ,
107
+ } ,
108
+ ] ,
109
+ } ) ;
110
+ } ) ;
111
+
112
+ it ( 'should stop the execution when aborted during object field completion with a custom error' , async ( ) => {
113
+ const abortController = new AbortController ( ) ;
114
+ const document = parse ( `
115
+ query {
116
+ todo {
117
+ id
118
+ author {
119
+ id
120
+ }
121
+ }
122
+ }
123
+ ` ) ;
124
+
125
+ const resultPromise = execute ( {
126
+ document,
127
+ schema,
128
+ abortSignal : abortController . signal ,
129
+ rootValue : {
130
+ todo : async ( ) =>
131
+ Promise . resolve ( {
132
+ id : '1' ,
133
+ text : 'Hello, World!' ,
134
+ /* c8 ignore next */
135
+ author : ( ) => expect . fail ( 'Should not be called' ) ,
136
+ } ) ,
137
+ } ,
138
+ } ) ;
139
+
140
+ const customError = new Error ( 'Custom abort error' ) ;
141
+ abortController . abort ( customError ) ;
142
+
143
+ const result = await resultPromise ;
144
+
145
+ expect ( result . errors ?. [ 0 ] . originalError ) . to . equal ( customError ) ;
146
+
147
+ expectJSON ( result ) . toDeepEqual ( {
148
+ data : {
149
+ todo : null ,
150
+ } ,
151
+ errors : [
152
+ {
153
+ message : 'Custom abort error' ,
154
+ path : [ 'todo' ] ,
155
+ locations : [ { line : 3 , column : 9 } ] ,
156
+ } ,
157
+ ] ,
158
+ } ) ;
159
+ } ) ;
160
+
161
+ it ( 'should stop the execution when aborted during object field completion with a custom string' , async ( ) => {
162
+ const abortController = new AbortController ( ) ;
163
+ const document = parse ( `
164
+ query {
165
+ todo {
166
+ id
167
+ author {
168
+ id
169
+ }
170
+ }
171
+ }
172
+ ` ) ;
173
+
174
+ const resultPromise = execute ( {
175
+ document,
176
+ schema,
177
+ abortSignal : abortController . signal ,
178
+ rootValue : {
179
+ todo : async ( ) =>
180
+ Promise . resolve ( {
181
+ id : '1' ,
182
+ text : 'Hello, World!' ,
183
+ /* c8 ignore next */
184
+ author : ( ) => expect . fail ( 'Should not be called' ) ,
185
+ } ) ,
186
+ } ,
187
+ } ) ;
188
+
189
+ abortController . abort ( 'Custom abort error message' ) ;
93
190
94
191
const result = await resultPromise ;
95
192
@@ -99,7 +196,7 @@ describe('Execute: Cancellation', () => {
99
196
} ,
100
197
errors : [
101
198
{
102
- message : 'Aborted ' ,
199
+ message : 'Unexpected error value: "Custom abort error message" ' ,
103
200
path : [ 'todo' ] ,
104
201
locations : [ { line : 3 , column : 9 } ] ,
105
202
} ,
@@ -135,7 +232,7 @@ describe('Execute: Cancellation', () => {
135
232
} ,
136
233
} ) ;
137
234
138
- abortController . abort ( 'Aborted' ) ;
235
+ abortController . abort ( ) ;
139
236
140
237
const result = await resultPromise ;
141
238
@@ -148,7 +245,7 @@ describe('Execute: Cancellation', () => {
148
245
} ,
149
246
errors : [
150
247
{
151
- message : 'Aborted ' ,
248
+ message : 'This operation was aborted ' ,
152
249
path : [ 'todo' , 'author' ] ,
153
250
locations : [ { line : 5 , column : 11 } ] ,
154
251
} ,
@@ -187,7 +284,7 @@ describe('Execute: Cancellation', () => {
187
284
abortSignal : abortController . signal ,
188
285
} ) ;
189
286
190
- abortController . abort ( 'Aborted' ) ;
287
+ abortController . abort ( ) ;
191
288
192
289
const result = await resultPromise ;
193
290
@@ -197,7 +294,7 @@ describe('Execute: Cancellation', () => {
197
294
} ,
198
295
errors : [
199
296
{
200
- message : 'Aborted ' ,
297
+ message : 'This operation was aborted ' ,
201
298
path : [ 'todo' ] ,
202
299
locations : [ { line : 3 , column : 9 } ] ,
203
300
} ,
@@ -242,7 +339,7 @@ describe('Execute: Cancellation', () => {
242
339
await resolveOnNextTick ( ) ;
243
340
await resolveOnNextTick ( ) ;
244
341
245
- abortController . abort ( 'Aborted' ) ;
342
+ abortController . abort ( ) ;
246
343
247
344
const result = await resultPromise ;
248
345
@@ -271,7 +368,7 @@ describe('Execute: Cancellation', () => {
271
368
line : 7 ,
272
369
} ,
273
370
] ,
274
- message : 'Aborted ' ,
371
+ message : 'This operation was aborted ' ,
275
372
path : [ 'todo' , 'author' ] ,
276
373
} ,
277
374
] ,
@@ -304,7 +401,7 @@ describe('Execute: Cancellation', () => {
304
401
} ,
305
402
} ) ;
306
403
307
- abortController . abort ( 'Aborted' ) ;
404
+ abortController . abort ( ) ;
308
405
309
406
const result = await resultPromise ;
310
407
@@ -315,7 +412,7 @@ describe('Execute: Cancellation', () => {
315
412
} ,
316
413
errors : [
317
414
{
318
- message : 'Aborted ' ,
415
+ message : 'This operation was aborted ' ,
319
416
path : [ 'bar' ] ,
320
417
locations : [ { line : 4 , column : 9 } ] ,
321
418
} ,
@@ -335,7 +432,7 @@ describe('Execute: Cancellation', () => {
335
432
}
336
433
}
337
434
` ) ;
338
- abortController . abort ( 'Aborted' ) ;
435
+ abortController . abort ( ) ;
339
436
const result = await execute ( {
340
437
document,
341
438
schema,
@@ -349,7 +446,7 @@ describe('Execute: Cancellation', () => {
349
446
expectJSON ( result ) . toDeepEqual ( {
350
447
errors : [
351
448
{
352
- message : 'Aborted ' ,
449
+ message : 'This operation was aborted ' ,
353
450
} ,
354
451
] ,
355
452
} ) ;
0 commit comments