@@ -239,20 +239,6 @@ function executeImpl(
239
239
return buildResponse(context, result);
240
240
}
241
241
242
- /**
243
- * Utility function to merge context's errors so far the errors in an
244
- * ExecutionPartialResult, zero the context's errors, and return the new
245
- * ExecutionPartialResult.
246
- */
247
- function mergeErrors (
248
- context : ExecutionContext ,
249
- result : ExecutionPartialResultNP < mixed > ,
250
- ): ExecutionPartialResultNP< mixed > {
251
- const errors = context . errors ;
252
- context . errors = [ ] ;
253
- return { data : result . data , errors : [ ...errors , ...( result . errors || [ ] ) ] } ;
254
- }
255
-
256
242
/**
257
243
* Given a completed execution context and data, build the { errors, data }
258
244
* response defined by the "Response" section of the GraphQL specification.
@@ -263,9 +249,7 @@ function buildResponse(
263
249
) {
264
250
const promise = getPromise ( result ) ;
265
251
if ( promise ) {
266
- return promise . then ( resolved =>
267
- buildResponse ( context , mergeErrors ( context , resolved ) ) ,
268
- ) ;
252
+ return promise . then ( resolved => buildResponse ( context , resolved ) ) ;
269
253
}
270
254
if ( result . data && ( ! result . errors || ! result . errors . length ) ) {
271
255
return { data : result . data } ;
@@ -440,13 +424,14 @@ function executeOperation(
440
424
: executeFields ( exeContext , type , rootValue , path , fields ) ;
441
425
const promise = getPromise ( result ) ;
442
426
if ( promise ) {
443
- return promise . then ( undefined , error =>
444
- mergeErrors ( exeContext , { data : null , errors : [ error ] } ) ,
445
- ) ;
427
+ return promise . then ( undefined , error => ( {
428
+ data : null ,
429
+ errors : [ error ] ,
430
+ } ) ) ;
446
431
}
447
- return mergeErrors ( exeContext , result ) ;
432
+ return result ;
448
433
} catch (error) {
449
- return mergeErrors ( exeContext , { data : null , errors : [ error ] } ) ;
434
+ return { data : null , errors : [ error ] } ;
450
435
}
451
436
}
452
437
@@ -587,7 +572,7 @@ function mergeEPRs(
587
572
( merged , value , i ) => {
588
573
merged . data [ keys [ i ] ] = value . data ;
589
574
if ( value . errors && value . errors . length ) {
590
- merged . errors . push . apply ( merged . errors , value . errors ) ;
575
+ merged . errors . push ( ... value . errors ) ;
591
576
}
592
577
return merged ;
593
578
} ,
@@ -1130,7 +1115,7 @@ function flattenEPRs(
1130
1115
forEach ( ( eprs : any ) , item => {
1131
1116
data . push ( item . data ) ;
1132
1117
if ( item . errors && item . errors . length ) {
1133
- errors . push . apply ( errors , item . errors ) ;
1118
+ errors . push ( ... item . errors ) ;
1134
1119
}
1135
1120
} ) ;
1136
1121
return { data , errors } ;
0 commit comments