@@ -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 : [ ... exeContext . errors , error as GraphQLError ] ,
398
398
} ;
399
399
} ,
400
400
) ;
@@ -406,17 +406,10 @@ 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 : [ ... exeContext . errors , error ] } ;
410
410
}
411
411
}
412
412
413
- function withError (
414
- errors : Array < GraphQLError > | undefined ,
415
- error : GraphQLError ,
416
- ) : ReadonlyArray < GraphQLError > {
417
- return errors === undefined ? [ error ] : [ ...errors , error ] ;
418
- }
419
-
420
413
function buildDataResponse (
421
414
exeContext : ExecutionContext ,
422
415
graphqlWrappedResult : GraphQLWrappedResult < ObjMap < unknown > > ,
@@ -425,7 +418,7 @@ function buildDataResponse(
425
418
const errors = exeContext . errors ;
426
419
if ( incrementalDataRecords === undefined ) {
427
420
exeContext . abortSignalListener ?. disconnect ( ) ;
428
- return errors !== undefined ? { errors, data } : { data } ;
421
+ return errors . length ? { errors, data } : { data } ;
429
422
}
430
423
431
424
return buildIncrementalResponse (
@@ -1005,12 +998,7 @@ function handleFieldError(
1005
998
// Otherwise, error protection is applied, logging the error and resolving
1006
999
// a null value for this field if one is encountered.
1007
1000
const context = incrementalContext ?? exeContext ;
1008
- let errors = context . errors ;
1009
- if ( errors === undefined ) {
1010
- errors = [ ] ;
1011
- context . errors = errors ;
1012
- }
1013
- errors . push ( error ) ;
1001
+ context . errors . push ( error ) ;
1014
1002
}
1015
1003
1016
1004
/**
@@ -2397,7 +2385,7 @@ function collectExecutionGroups(
2397
2385
path ,
2398
2386
groupedFieldSet ,
2399
2387
{
2400
- errors : undefined ,
2388
+ errors : [ ] ,
2401
2389
completed : false ,
2402
2390
deferUsageSet,
2403
2391
} ,
@@ -2462,7 +2450,7 @@ function executeExecutionGroup(
2462
2450
return {
2463
2451
pendingExecutionGroup,
2464
2452
path : pathToArray ( path ) ,
2465
- errors : withError ( incrementalContext . errors , error ) ,
2453
+ errors : [ ... incrementalContext . errors , error ] ,
2466
2454
} ;
2467
2455
}
2468
2456
@@ -2482,7 +2470,7 @@ function executeExecutionGroup(
2482
2470
return {
2483
2471
pendingExecutionGroup,
2484
2472
path : pathToArray ( path ) ,
2485
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2473
+ errors : [ ... incrementalContext . errors , error as GraphQLError ] ,
2486
2474
} ;
2487
2475
} ,
2488
2476
) ;
@@ -2498,7 +2486,7 @@ function executeExecutionGroup(
2498
2486
}
2499
2487
2500
2488
function buildCompletedExecutionGroup (
2501
- errors : ReadonlyArray < GraphQLError > | undefined ,
2489
+ errors : ReadonlyArray < GraphQLError > ,
2502
2490
pendingExecutionGroup : PendingExecutionGroup ,
2503
2491
path : Path | undefined ,
2504
2492
result : GraphQLWrappedResult < ObjMap < unknown > > ,
@@ -2507,7 +2495,7 @@ function buildCompletedExecutionGroup(
2507
2495
return {
2508
2496
pendingExecutionGroup,
2509
2497
path : pathToArray ( path ) ,
2510
- result : errors === undefined ? { data } : { data, errors } ,
2498
+ result : errors . length ? { errors , data } : { data } ,
2511
2499
incrementalDataRecords,
2512
2500
} ;
2513
2501
}
@@ -2543,7 +2531,7 @@ function buildSyncStreamItemQueue(
2543
2531
initialPath ,
2544
2532
initialItem ,
2545
2533
exeContext ,
2546
- { errors : undefined , completed : false } ,
2534
+ { errors : [ ] , completed : false } ,
2547
2535
fieldDetailsList ,
2548
2536
info ,
2549
2537
itemType ,
@@ -2560,7 +2548,7 @@ function buildSyncStreamItemQueue(
2560
2548
/* c8 ignore next 6 */
2561
2549
if ( currentStreamItem instanceof BoxedPromiseOrValue ) {
2562
2550
const result = currentStreamItem . value ;
2563
- if ( ! isPromise ( result ) && result . errors ! == undefined ) {
2551
+ if ( ! isPromise ( result ) && result . item = == undefined ) {
2564
2552
break ;
2565
2553
}
2566
2554
}
@@ -2574,7 +2562,7 @@ function buildSyncStreamItemQueue(
2574
2562
itemPath ,
2575
2563
value ,
2576
2564
exeContext ,
2577
- { errors : undefined , completed : false } ,
2565
+ { errors : [ ] , completed : false } ,
2578
2566
fieldDetailsList ,
2579
2567
info ,
2580
2568
itemType ,
@@ -2666,7 +2654,7 @@ async function getNextAsyncStreamItemResult(
2666
2654
itemPath ,
2667
2655
iteration . value ,
2668
2656
exeContext ,
2669
- { errors : undefined , completed : false } ,
2657
+ { errors : [ ] , completed : false } ,
2670
2658
fieldDetailsList ,
2671
2659
info ,
2672
2660
itemType ,
@@ -2724,7 +2712,7 @@ function completeStreamItem(
2724
2712
( error : unknown ) => {
2725
2713
incrementalContext . completed = true ;
2726
2714
return {
2727
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2715
+ errors : [ ... incrementalContext . errors , error as GraphQLError ] ,
2728
2716
} ;
2729
2717
} ,
2730
2718
) ;
@@ -2757,7 +2745,7 @@ function completeStreamItem(
2757
2745
} catch ( error ) {
2758
2746
incrementalContext . completed = true ;
2759
2747
return {
2760
- errors : withError ( incrementalContext . errors , error ) ,
2748
+ errors : [ ... incrementalContext . errors , error ] ,
2761
2749
} ;
2762
2750
}
2763
2751
@@ -2782,7 +2770,7 @@ function completeStreamItem(
2782
2770
( error : unknown ) => {
2783
2771
incrementalContext . completed = true ;
2784
2772
return {
2785
- errors : withError ( incrementalContext . errors , error as GraphQLError ) ,
2773
+ errors : [ ... incrementalContext . errors , error as GraphQLError ] ,
2786
2774
} ;
2787
2775
} ,
2788
2776
) ;
@@ -2793,7 +2781,7 @@ function completeStreamItem(
2793
2781
}
2794
2782
2795
2783
function buildStreamItemResult (
2796
- errors : ReadonlyArray < GraphQLError > | undefined ,
2784
+ errors : ReadonlyArray < GraphQLError > ,
2797
2785
result : GraphQLWrappedResult < unknown > ,
2798
2786
) : StreamItemResult {
2799
2787
const { rawResult : item , incrementalDataRecords } = result ;
0 commit comments