@@ -214,7 +214,7 @@ export interface StreamUsage {
214
214
215
215
interface GraphQLWrappedResult < T > {
216
216
rawResult : T ;
217
- incrementalDataRecords : Array < IncrementalDataRecord > | undefined ;
217
+ incrementalDataRecords : Array < IncrementalDataRecord > ;
218
218
}
219
219
220
220
const UNEXPECTED_EXPERIMENTAL_DIRECTIVES =
@@ -424,7 +424,7 @@ function buildDataResponse(
424
424
) : ExecutionResult | ExperimentalIncrementalExecutionResults {
425
425
const { rawResult : data , incrementalDataRecords } = graphqlWrappedResult ;
426
426
const errors = exeContext . errors ;
427
- if ( incrementalDataRecords === undefined ) {
427
+ if ( incrementalDataRecords . length === 0 ) {
428
428
exeContext . abortSignalListener ?. disconnect ( ) ;
429
429
return errors . length ? { errors, data } : { data } ;
430
430
}
@@ -626,12 +626,12 @@ function withNewExecutionGroups(
626
626
) : PromiseOrValue < GraphQLWrappedResult < ObjMap < unknown > > > {
627
627
if ( isPromise ( result ) ) {
628
628
return result . then ( ( resolved ) => {
629
- addIncrementalDataRecords ( resolved , newPendingExecutionGroups ) ;
629
+ resolved . incrementalDataRecords . push ( ... newPendingExecutionGroups ) ;
630
630
return resolved ;
631
631
} ) ;
632
632
}
633
633
634
- addIncrementalDataRecords ( result , newPendingExecutionGroups ) ;
634
+ result . incrementalDataRecords . push ( ... newPendingExecutionGroups ) ;
635
635
return result ;
636
636
}
637
637
@@ -726,41 +726,25 @@ function executeFieldsSerially(
726
726
if ( isPromise ( result ) ) {
727
727
return result . then ( ( resolved ) => {
728
728
graphqlWrappedResult . rawResult [ responseName ] = resolved . rawResult ;
729
- addIncrementalDataRecords (
730
- graphqlWrappedResult ,
731
- resolved . incrementalDataRecords ,
729
+ graphqlWrappedResult . incrementalDataRecords . push (
730
+ ...resolved . incrementalDataRecords ,
732
731
) ;
733
732
return graphqlWrappedResult ;
734
733
} ) ;
735
734
}
736
735
graphqlWrappedResult . rawResult [ responseName ] = result . rawResult ;
737
- addIncrementalDataRecords (
738
- graphqlWrappedResult ,
739
- result . incrementalDataRecords ,
736
+ graphqlWrappedResult . incrementalDataRecords . push (
737
+ ...result . incrementalDataRecords ,
740
738
) ;
741
739
return graphqlWrappedResult ;
742
740
} ,
743
741
{
744
742
rawResult : Object . create ( null ) ,
745
- incrementalDataRecords : undefined ,
743
+ incrementalDataRecords : [ ] as Array < IncrementalDataRecord > ,
746
744
} ,
747
745
) ;
748
746
}
749
747
750
- function addIncrementalDataRecords (
751
- graphqlWrappedResult : GraphQLWrappedResult < unknown > ,
752
- incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > | undefined ,
753
- ) : void {
754
- if ( incrementalDataRecords === undefined ) {
755
- return ;
756
- }
757
- if ( graphqlWrappedResult . incrementalDataRecords === undefined ) {
758
- graphqlWrappedResult . incrementalDataRecords = [ ...incrementalDataRecords ] ;
759
- } else {
760
- graphqlWrappedResult . incrementalDataRecords . push ( ...incrementalDataRecords ) ;
761
- }
762
- }
763
-
764
748
/**
765
749
* Implements the "Executing selection sets" section of the spec
766
750
* for fields that may be executed in parallel.
@@ -777,7 +761,7 @@ function executeFields(
777
761
const results = Object . create ( null ) ;
778
762
const graphqlWrappedResult : GraphQLWrappedResult < ObjMap < unknown > > = {
779
763
rawResult : results ,
780
- incrementalDataRecords : undefined ,
764
+ incrementalDataRecords : [ ] ,
781
765
} ;
782
766
let containsPromise = false ;
783
767
@@ -797,18 +781,16 @@ function executeFields(
797
781
if ( result !== undefined ) {
798
782
if ( isPromise ( result ) ) {
799
783
results [ responseName ] = result . then ( ( resolved ) => {
800
- addIncrementalDataRecords (
801
- graphqlWrappedResult ,
802
- resolved . incrementalDataRecords ,
784
+ graphqlWrappedResult . incrementalDataRecords . push (
785
+ ...resolved . incrementalDataRecords ,
803
786
) ;
804
787
return resolved . rawResult ;
805
788
} ) ;
806
789
containsPromise = true ;
807
790
} else {
808
791
results [ responseName ] = result . rawResult ;
809
- addIncrementalDataRecords (
810
- graphqlWrappedResult ,
811
- result . incrementalDataRecords ,
792
+ graphqlWrappedResult . incrementalDataRecords . push (
793
+ ...result . incrementalDataRecords ,
812
794
) ;
813
795
}
814
796
}
@@ -935,7 +917,7 @@ function executeField(
935
917
path ,
936
918
incrementalContext ,
937
919
) ;
938
- return { rawResult : null , incrementalDataRecords : undefined } ;
920
+ return { rawResult : null , incrementalDataRecords : [ ] } ;
939
921
} ) ;
940
922
}
941
923
return completed ;
@@ -948,7 +930,7 @@ function executeField(
948
930
path ,
949
931
incrementalContext ,
950
932
) ;
951
- return { rawResult : null , incrementalDataRecords : undefined } ;
933
+ return { rawResult : null , incrementalDataRecords : [ ] } ;
952
934
}
953
935
}
954
936
@@ -1068,7 +1050,7 @@ function completeValue(
1068
1050
1069
1051
// If result value is null or undefined then return null.
1070
1052
if ( result == null ) {
1071
- return { rawResult : null , incrementalDataRecords : undefined } ;
1053
+ return { rawResult : null , incrementalDataRecords : [ ] } ;
1072
1054
}
1073
1055
1074
1056
// If field type is List, complete each item in the list with the inner type
@@ -1090,7 +1072,7 @@ function completeValue(
1090
1072
if ( isLeafType ( returnType ) ) {
1091
1073
return {
1092
1074
rawResult : completeLeafValue ( returnType , result ) ,
1093
- incrementalDataRecords : undefined ,
1075
+ incrementalDataRecords : [ ] ,
1094
1076
} ;
1095
1077
}
1096
1078
@@ -1169,7 +1151,7 @@ async function completePromisedValue(
1169
1151
path ,
1170
1152
incrementalContext ,
1171
1153
) ;
1172
- return { rawResult : null , incrementalDataRecords : undefined } ;
1154
+ return { rawResult : null , incrementalDataRecords : [ ] } ;
1173
1155
}
1174
1156
}
1175
1157
@@ -1269,7 +1251,7 @@ async function completeAsyncIteratorValue(
1269
1251
const completedResults : Array < unknown > = [ ] ;
1270
1252
const graphqlWrappedResult : GraphQLWrappedResult < Array < unknown > > = {
1271
1253
rawResult : completedResults ,
1272
- incrementalDataRecords : undefined ,
1254
+ incrementalDataRecords : [ ] ,
1273
1255
} ;
1274
1256
let index = 0 ;
1275
1257
const streamUsage = getStreamUsage (
@@ -1312,7 +1294,7 @@ async function completeAsyncIteratorValue(
1312
1294
exeContext . cancellableStreams . add ( streamRecord ) ;
1313
1295
}
1314
1296
1315
- addIncrementalDataRecords ( graphqlWrappedResult , [ streamRecord ] ) ;
1297
+ graphqlWrappedResult . incrementalDataRecords . push ( streamRecord ) ;
1316
1298
break ;
1317
1299
}
1318
1300
@@ -1462,7 +1444,7 @@ function completeIterableValue(
1462
1444
const completedResults : Array < unknown > = [ ] ;
1463
1445
const graphqlWrappedResult : GraphQLWrappedResult < Array < unknown > > = {
1464
1446
rawResult : completedResults ,
1465
- incrementalDataRecords : undefined ,
1447
+ incrementalDataRecords : [ ] ,
1466
1448
} ;
1467
1449
let index = 0 ;
1468
1450
const streamUsage = getStreamUsage (
@@ -1491,7 +1473,7 @@ function completeIterableValue(
1491
1473
) ,
1492
1474
} ;
1493
1475
1494
- addIncrementalDataRecords ( graphqlWrappedResult , [ syncStreamRecord ] ) ;
1476
+ graphqlWrappedResult . incrementalDataRecords . push ( syncStreamRecord ) ;
1495
1477
break ;
1496
1478
}
1497
1479
@@ -1578,7 +1560,9 @@ function completeListItemValue(
1578
1560
completedResults . push (
1579
1561
completedItem . then (
1580
1562
( resolved ) => {
1581
- addIncrementalDataRecords ( parent , resolved . incrementalDataRecords ) ;
1563
+ parent . incrementalDataRecords . push (
1564
+ ...resolved . incrementalDataRecords ,
1565
+ ) ;
1582
1566
return resolved . rawResult ;
1583
1567
} ,
1584
1568
( rawError : unknown ) => {
@@ -1598,7 +1582,7 @@ function completeListItemValue(
1598
1582
}
1599
1583
1600
1584
completedResults . push ( completedItem . rawResult ) ;
1601
- addIncrementalDataRecords ( parent , completedItem . incrementalDataRecords ) ;
1585
+ parent . incrementalDataRecords . push ( ... completedItem . incrementalDataRecords ) ;
1602
1586
} catch ( rawError ) {
1603
1587
handleFieldError (
1604
1588
rawError ,
@@ -1643,7 +1627,7 @@ async function completePromisedListItemValue(
1643
1627
if ( isPromise ( completed ) ) {
1644
1628
completed = await completed ;
1645
1629
}
1646
- addIncrementalDataRecords ( parent , completed . incrementalDataRecords ) ;
1630
+ parent . incrementalDataRecords . push ( ... completed . incrementalDataRecords ) ;
1647
1631
return completed . rawResult ;
1648
1632
} catch ( rawError ) {
1649
1633
handleFieldError (
@@ -2748,7 +2732,7 @@ function completeStreamItem(
2748
2732
itemPath ,
2749
2733
incrementalContext ,
2750
2734
) ;
2751
- result = { rawResult : null , incrementalDataRecords : undefined } ;
2735
+ result = { rawResult : null , incrementalDataRecords : [ ] } ;
2752
2736
}
2753
2737
} catch ( error ) {
2754
2738
incrementalContext . completed = true ;
@@ -2768,7 +2752,7 @@ function completeStreamItem(
2768
2752
itemPath ,
2769
2753
incrementalContext ,
2770
2754
) ;
2771
- return { rawResult : null , incrementalDataRecords : undefined } ;
2755
+ return { rawResult : null , incrementalDataRecords : [ ] } ;
2772
2756
} )
2773
2757
. then (
2774
2758
( resolvedItem ) => {
0 commit comments