@@ -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
}
@@ -338,7 +338,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
338
338
const abortSignal = validatedExecutionArgs . abortSignal ;
339
339
const exeContext : ExecutionContext = {
340
340
validatedExecutionArgs,
341
- errors : undefined ,
341
+ errors : [ ] ,
342
342
abortSignalListener : abortSignal
343
343
? new AbortSignalListener ( abortSignal )
344
344
: undefined ,
@@ -395,7 +395,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
395
395
exeContext . abortSignalListener ?. disconnect ( ) ;
396
396
return {
397
397
data : null ,
398
- errors : withError ( exeContext . errors , error as GraphQLError ) ,
398
+ errors : [ ... exeContext . errors , error as GraphQLError ] ,
399
399
} ;
400
400
} ,
401
401
) ;
@@ -407,17 +407,10 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
407
407
// TODO: add test case for synchronous null bubbling to root with cancellation
408
408
/* c8 ignore next */
409
409
exeContext . abortSignalListener ?. disconnect ( ) ;
410
- return { data : null , errors : withError ( exeContext . errors , error ) } ;
410
+ return { data : null , errors : [ ... exeContext . errors , error ] } ;
411
411
}
412
412
}
413
413
414
- function withError (
415
- errors : Array < GraphQLError > | undefined ,
416
- error : GraphQLError ,
417
- ) : ReadonlyArray < GraphQLError > {
418
- return errors === undefined ? [ error ] : [ ...errors , error ] ;
419
- }
420
-
421
414
function buildDataResponse (
422
415
exeContext : ExecutionContext ,
423
416
graphqlWrappedResult : GraphQLWrappedResult < ObjMap < unknown > > ,
@@ -430,7 +423,7 @@ function buildDataResponse(
430
423
const errors = exeContext . errors ;
431
424
if ( incrementalDataRecords === undefined ) {
432
425
exeContext . abortSignalListener ?. disconnect ( ) ;
433
- return errors !== undefined ? { errors, data } : { data } ;
426
+ return errors . length ? { errors, data } : { data } ;
434
427
}
435
428
436
429
return buildIncrementalResponse (
@@ -1076,12 +1069,7 @@ function handleFieldError(
1076
1069
// Otherwise, error protection is applied, logging the error and resolving
1077
1070
// a null value for this field if one is encountered.
1078
1071
const context = incrementalContext ?? exeContext ;
1079
- let errors = context . errors ;
1080
- if ( errors === undefined ) {
1081
- errors = [ ] ;
1082
- context . errors = errors ;
1083
- }
1084
- errors . push ( error ) ;
1072
+ context . errors . push ( error ) ;
1085
1073
}
1086
1074
1087
1075
/**
@@ -2513,7 +2501,7 @@ function collectExecutionGroups(
2513
2501
path ,
2514
2502
groupedFieldSet ,
2515
2503
{
2516
- errors : undefined ,
2504
+ errors : [ ] ,
2517
2505
completed : false ,
2518
2506
deferUsageSet,
2519
2507
} ,
@@ -2578,7 +2566,7 @@ function executeExecutionGroup(
2578
2566
return {
2579
2567
pendingExecutionGroup,
2580
2568
path : pathToArray ( path ) ,
2581
- errors : withError ( incrementalContext . errors , error ) ,
2569
+ errors : [ ... incrementalContext . errors , error ] ,
2582
2570
} ;
2583
2571
}
2584
2572
@@ -2598,7 +2586,7 @@ function executeExecutionGroup(
2598
2586
return {
2599
2587
pendingExecutionGroup,
2600
2588
path : pathToArray ( path ) ,
2601
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2589
+ errors : [ ... incrementalContext . errors , error as GraphQLError ] ,
2602
2590
} ;
2603
2591
} ,
2604
2592
) ;
@@ -2614,7 +2602,7 @@ function executeExecutionGroup(
2614
2602
}
2615
2603
2616
2604
function buildCompletedExecutionGroup (
2617
- errors : ReadonlyArray < GraphQLError > | undefined ,
2605
+ errors : ReadonlyArray < GraphQLError > ,
2618
2606
pendingExecutionGroup : PendingExecutionGroup ,
2619
2607
path : Path | undefined ,
2620
2608
result : GraphQLWrappedResult < ObjMap < unknown > > ,
@@ -2627,7 +2615,7 @@ function buildCompletedExecutionGroup(
2627
2615
return {
2628
2616
pendingExecutionGroup,
2629
2617
path : pathToArray ( path ) ,
2630
- result : errors === undefined ? { data } : { data, errors } ,
2618
+ result : errors . length ? { errors , data } : { data } ,
2631
2619
newDeferredFragmentRecords,
2632
2620
incrementalDataRecords,
2633
2621
} ;
@@ -2664,7 +2652,7 @@ function buildSyncStreamItemQueue(
2664
2652
initialPath ,
2665
2653
initialItem ,
2666
2654
exeContext ,
2667
- { errors : undefined , completed : false } ,
2655
+ { errors : [ ] , completed : false } ,
2668
2656
fieldDetailsList ,
2669
2657
info ,
2670
2658
itemType ,
@@ -2681,7 +2669,7 @@ function buildSyncStreamItemQueue(
2681
2669
/* c8 ignore next 6 */
2682
2670
if ( currentStreamItem instanceof BoxedPromiseOrValue ) {
2683
2671
const result = currentStreamItem . value ;
2684
- if ( ! isPromise ( result ) && result . errors ! == undefined ) {
2672
+ if ( ! isPromise ( result ) && result . item = == undefined ) {
2685
2673
break ;
2686
2674
}
2687
2675
}
@@ -2695,7 +2683,7 @@ function buildSyncStreamItemQueue(
2695
2683
itemPath ,
2696
2684
value ,
2697
2685
exeContext ,
2698
- { errors : undefined , completed : false } ,
2686
+ { errors : [ ] , completed : false } ,
2699
2687
fieldDetailsList ,
2700
2688
info ,
2701
2689
itemType ,
@@ -2787,7 +2775,7 @@ async function getNextAsyncStreamItemResult(
2787
2775
itemPath ,
2788
2776
iteration . value ,
2789
2777
exeContext ,
2790
- { errors : undefined , completed : false } ,
2778
+ { errors : [ ] , completed : false } ,
2791
2779
fieldDetailsList ,
2792
2780
info ,
2793
2781
itemType ,
@@ -2845,7 +2833,7 @@ function completeStreamItem(
2845
2833
( error : unknown ) => {
2846
2834
incrementalContext . completed = true ;
2847
2835
return {
2848
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2836
+ errors : [ ... incrementalContext . errors , error as GraphQLError ] ,
2849
2837
} ;
2850
2838
} ,
2851
2839
) ;
@@ -2882,7 +2870,7 @@ function completeStreamItem(
2882
2870
} catch ( error ) {
2883
2871
incrementalContext . completed = true ;
2884
2872
return {
2885
- errors : withError ( incrementalContext . errors , error ) ,
2873
+ errors : [ ... incrementalContext . errors , error ] ,
2886
2874
} ;
2887
2875
}
2888
2876
@@ -2911,7 +2899,7 @@ function completeStreamItem(
2911
2899
( error : unknown ) => {
2912
2900
incrementalContext . completed = true ;
2913
2901
return {
2914
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2902
+ errors : [ ... incrementalContext . errors , error as GraphQLError ] ,
2915
2903
} ;
2916
2904
} ,
2917
2905
) ;
@@ -2922,7 +2910,7 @@ function completeStreamItem(
2922
2910
}
2923
2911
2924
2912
function buildStreamItemResult (
2925
- errors : ReadonlyArray < GraphQLError > | undefined ,
2913
+ errors : ReadonlyArray < GraphQLError > ,
2926
2914
result : GraphQLWrappedResult < unknown > ,
2927
2915
) : StreamItemResult {
2928
2916
const {
0 commit comments