@@ -168,15 +168,15 @@ export interface ValidatedExecutionArgs {
168
168
169
169
export interface ExecutionContext {
170
170
validatedExecutionArgs : ValidatedExecutionArgs ;
171
- errors : Array < GraphQLError > | undefined ;
171
+ errors : Array < GraphQLError > ;
172
172
abortSignalListener : AbortSignalListener | undefined ;
173
173
completed : boolean ;
174
174
cancellableStreams : Set < CancellableStreamRecord > | undefined ;
175
175
errorPropagation : boolean ;
176
176
}
177
177
178
178
interface IncrementalContext {
179
- errors : Array < GraphQLError > | undefined ;
179
+ errors : Array < GraphQLError > ;
180
180
completed : boolean ;
181
181
deferUsageSet ?: DeferUsageSet | undefined ;
182
182
}
@@ -337,7 +337,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
337
337
const abortSignal = validatedExecutionArgs . abortSignal ;
338
338
const exeContext : ExecutionContext = {
339
339
validatedExecutionArgs,
340
- errors : undefined ,
340
+ errors : [ ] ,
341
341
abortSignalListener : abortSignal
342
342
? new AbortSignalListener ( abortSignal )
343
343
: undefined ,
@@ -394,7 +394,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
394
394
exeContext . abortSignalListener ?. disconnect ( ) ;
395
395
return {
396
396
data : null ,
397
- errors : withError ( exeContext . errors , error as GraphQLError ) ,
397
+ errors : addError ( exeContext . errors , error as GraphQLError ) ,
398
398
} ;
399
399
} ,
400
400
) ;
@@ -406,15 +406,16 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
406
406
// TODO: add test case for synchronous null bubbling to root with cancellation
407
407
/* c8 ignore next */
408
408
exeContext . abortSignalListener ?. disconnect ( ) ;
409
- return { data : null , errors : withError ( exeContext . errors , error ) } ;
409
+ return { data : null , errors : addError ( exeContext . errors , error ) } ;
410
410
}
411
411
}
412
412
413
- function withError (
414
- errors : Array < GraphQLError > | undefined ,
413
+ function addError (
414
+ errors : Array < GraphQLError > ,
415
415
error : GraphQLError ,
416
416
) : ReadonlyArray < GraphQLError > {
417
- return errors === undefined ? [ error ] : [ ...errors , error ] ;
417
+ errors . push ( error ) ;
418
+ return errors ;
418
419
}
419
420
420
421
function buildDataResponse (
@@ -425,7 +426,7 @@ function buildDataResponse(
425
426
const errors = exeContext . errors ;
426
427
if ( incrementalDataRecords === undefined ) {
427
428
exeContext . abortSignalListener ?. disconnect ( ) ;
428
- return errors !== undefined ? { errors, data } : { data } ;
429
+ return errors . length ? { errors, data } : { data } ;
429
430
}
430
431
431
432
return buildIncrementalResponse (
@@ -1005,12 +1006,7 @@ function handleFieldError(
1005
1006
// Otherwise, error protection is applied, logging the error and resolving
1006
1007
// a null value for this field if one is encountered.
1007
1008
const context = incrementalContext ?? exeContext ;
1008
- let errors = context . errors ;
1009
- if ( errors === undefined ) {
1010
- errors = [ ] ;
1011
- context . errors = errors ;
1012
- }
1013
- errors . push ( error ) ;
1009
+ addError ( context . errors , error ) ;
1014
1010
}
1015
1011
1016
1012
/**
@@ -2397,7 +2393,7 @@ function collectExecutionGroups(
2397
2393
path ,
2398
2394
groupedFieldSet ,
2399
2395
{
2400
- errors : undefined ,
2396
+ errors : [ ] ,
2401
2397
completed : false ,
2402
2398
deferUsageSet,
2403
2399
} ,
@@ -2462,7 +2458,7 @@ function executeExecutionGroup(
2462
2458
return {
2463
2459
pendingExecutionGroup,
2464
2460
path : pathToArray ( path ) ,
2465
- errors : withError ( incrementalContext . errors , error ) ,
2461
+ errors : addError ( incrementalContext . errors , error ) ,
2466
2462
} ;
2467
2463
}
2468
2464
@@ -2482,7 +2478,7 @@ function executeExecutionGroup(
2482
2478
return {
2483
2479
pendingExecutionGroup,
2484
2480
path : pathToArray ( path ) ,
2485
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2481
+ errors : addError ( incrementalContext . errors , error as GraphQLError ) ,
2486
2482
} ;
2487
2483
} ,
2488
2484
) ;
@@ -2498,7 +2494,7 @@ function executeExecutionGroup(
2498
2494
}
2499
2495
2500
2496
function buildCompletedExecutionGroup (
2501
- errors : ReadonlyArray < GraphQLError > | undefined ,
2497
+ errors : ReadonlyArray < GraphQLError > ,
2502
2498
pendingExecutionGroup : PendingExecutionGroup ,
2503
2499
path : Path | undefined ,
2504
2500
result : GraphQLWrappedResult < ObjMap < unknown > > ,
@@ -2507,7 +2503,7 @@ function buildCompletedExecutionGroup(
2507
2503
return {
2508
2504
pendingExecutionGroup,
2509
2505
path : pathToArray ( path ) ,
2510
- result : errors === undefined ? { data } : { data, errors } ,
2506
+ result : errors . length ? { errors , data } : { data } ,
2511
2507
incrementalDataRecords,
2512
2508
} ;
2513
2509
}
@@ -2543,7 +2539,7 @@ function buildSyncStreamItemQueue(
2543
2539
initialPath ,
2544
2540
initialItem ,
2545
2541
exeContext ,
2546
- { errors : undefined , completed : false } ,
2542
+ { errors : [ ] , completed : false } ,
2547
2543
fieldDetailsList ,
2548
2544
info ,
2549
2545
itemType ,
@@ -2560,7 +2556,7 @@ function buildSyncStreamItemQueue(
2560
2556
/* c8 ignore next 6 */
2561
2557
if ( currentStreamItem instanceof BoxedPromiseOrValue ) {
2562
2558
const result = currentStreamItem . value ;
2563
- if ( ! isPromise ( result ) && result . errors ! == undefined ) {
2559
+ if ( ! isPromise ( result ) && result . item = == undefined ) {
2564
2560
break ;
2565
2561
}
2566
2562
}
@@ -2574,7 +2570,7 @@ function buildSyncStreamItemQueue(
2574
2570
itemPath ,
2575
2571
value ,
2576
2572
exeContext ,
2577
- { errors : undefined , completed : false } ,
2573
+ { errors : [ ] , completed : false } ,
2578
2574
fieldDetailsList ,
2579
2575
info ,
2580
2576
itemType ,
@@ -2666,7 +2662,7 @@ async function getNextAsyncStreamItemResult(
2666
2662
itemPath ,
2667
2663
iteration . value ,
2668
2664
exeContext ,
2669
- { errors : undefined , completed : false } ,
2665
+ { errors : [ ] , completed : false } ,
2670
2666
fieldDetailsList ,
2671
2667
info ,
2672
2668
itemType ,
@@ -2724,7 +2720,7 @@ function completeStreamItem(
2724
2720
( error : unknown ) => {
2725
2721
incrementalContext . completed = true ;
2726
2722
return {
2727
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2723
+ errors : addError ( incrementalContext . errors , error as GraphQLError ) ,
2728
2724
} ;
2729
2725
} ,
2730
2726
) ;
@@ -2757,7 +2753,7 @@ function completeStreamItem(
2757
2753
} catch ( error ) {
2758
2754
incrementalContext . completed = true ;
2759
2755
return {
2760
- errors : withError ( incrementalContext . errors , error ) ,
2756
+ errors : addError ( incrementalContext . errors , error ) ,
2761
2757
} ;
2762
2758
}
2763
2759
@@ -2782,7 +2778,7 @@ function completeStreamItem(
2782
2778
( error : unknown ) => {
2783
2779
incrementalContext . completed = true ;
2784
2780
return {
2785
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2781
+ errors : addError ( incrementalContext . errors , error as GraphQLError ) ,
2786
2782
} ;
2787
2783
} ,
2788
2784
) ;
@@ -2793,7 +2789,7 @@ function completeStreamItem(
2793
2789
}
2794
2790
2795
2791
function buildStreamItemResult (
2796
- errors : ReadonlyArray < GraphQLError > | undefined ,
2792
+ errors : ReadonlyArray < GraphQLError > ,
2797
2793
result : GraphQLWrappedResult < unknown > ,
2798
2794
) : StreamItemResult {
2799
2795
const { rawResult : item , incrementalDataRecords } = result ;
0 commit comments