@@ -214,7 +214,7 @@ export interface StreamUsage {
214214
215215interface GraphQLWrappedResult < T > {
216216 rawResult : T ;
217- incrementalDataRecords : Array < IncrementalDataRecord > | undefined ;
217+ incrementalDataRecords : Array < IncrementalDataRecord > ;
218218}
219219
220220const UNEXPECTED_EXPERIMENTAL_DIRECTIVES =
@@ -424,7 +424,7 @@ function buildDataResponse(
424424) : ExecutionResult | ExperimentalIncrementalExecutionResults {
425425 const { rawResult : data , incrementalDataRecords } = graphqlWrappedResult ;
426426 const errors = exeContext . errors ;
427- if ( incrementalDataRecords === undefined ) {
427+ if ( incrementalDataRecords . length === 0 ) {
428428 exeContext . abortSignalListener ?. disconnect ( ) ;
429429 return errors . length ? { errors, data } : { data } ;
430430 }
@@ -626,12 +626,12 @@ function withNewExecutionGroups(
626626) : PromiseOrValue < GraphQLWrappedResult < ObjMap < unknown > > > {
627627 if ( isPromise ( result ) ) {
628628 return result . then ( ( resolved ) => {
629- addIncrementalDataRecords ( resolved , newPendingExecutionGroups ) ;
629+ resolved . incrementalDataRecords . push ( ... newPendingExecutionGroups ) ;
630630 return resolved ;
631631 } ) ;
632632 }
633633
634- addIncrementalDataRecords ( result , newPendingExecutionGroups ) ;
634+ result . incrementalDataRecords . push ( ... newPendingExecutionGroups ) ;
635635 return result ;
636636}
637637
@@ -726,41 +726,25 @@ function executeFieldsSerially(
726726 if ( isPromise ( result ) ) {
727727 return result . then ( ( resolved ) => {
728728 graphqlWrappedResult . rawResult [ responseName ] = resolved . rawResult ;
729- addIncrementalDataRecords (
730- graphqlWrappedResult ,
731- resolved . incrementalDataRecords ,
729+ graphqlWrappedResult . incrementalDataRecords . push (
730+ ...resolved . incrementalDataRecords ,
732731 ) ;
733732 return graphqlWrappedResult ;
734733 } ) ;
735734 }
736735 graphqlWrappedResult . rawResult [ responseName ] = result . rawResult ;
737- addIncrementalDataRecords (
738- graphqlWrappedResult ,
739- result . incrementalDataRecords ,
736+ graphqlWrappedResult . incrementalDataRecords . push (
737+ ...result . incrementalDataRecords ,
740738 ) ;
741739 return graphqlWrappedResult ;
742740 } ,
743741 {
744742 rawResult : Object . create ( null ) ,
745- incrementalDataRecords : undefined ,
743+ incrementalDataRecords : [ ] as Array < IncrementalDataRecord > ,
746744 } ,
747745 ) ;
748746}
749747
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-
764748/**
765749 * Implements the "Executing selection sets" section of the spec
766750 * for fields that may be executed in parallel.
@@ -777,7 +761,7 @@ function executeFields(
777761 const results = Object . create ( null ) ;
778762 const graphqlWrappedResult : GraphQLWrappedResult < ObjMap < unknown > > = {
779763 rawResult : results ,
780- incrementalDataRecords : undefined ,
764+ incrementalDataRecords : [ ] ,
781765 } ;
782766 let containsPromise = false ;
783767
@@ -797,18 +781,16 @@ function executeFields(
797781 if ( result !== undefined ) {
798782 if ( isPromise ( result ) ) {
799783 results [ responseName ] = result . then ( ( resolved ) => {
800- addIncrementalDataRecords (
801- graphqlWrappedResult ,
802- resolved . incrementalDataRecords ,
784+ graphqlWrappedResult . incrementalDataRecords . push (
785+ ...resolved . incrementalDataRecords ,
803786 ) ;
804787 return resolved . rawResult ;
805788 } ) ;
806789 containsPromise = true ;
807790 } else {
808791 results [ responseName ] = result . rawResult ;
809- addIncrementalDataRecords (
810- graphqlWrappedResult ,
811- result . incrementalDataRecords ,
792+ graphqlWrappedResult . incrementalDataRecords . push (
793+ ...result . incrementalDataRecords ,
812794 ) ;
813795 }
814796 }
@@ -935,7 +917,7 @@ function executeField(
935917 path ,
936918 incrementalContext ,
937919 ) ;
938- return { rawResult : null , incrementalDataRecords : undefined } ;
920+ return { rawResult : null , incrementalDataRecords : [ ] } ;
939921 } ) ;
940922 }
941923 return completed ;
@@ -948,7 +930,7 @@ function executeField(
948930 path ,
949931 incrementalContext ,
950932 ) ;
951- return { rawResult : null , incrementalDataRecords : undefined } ;
933+ return { rawResult : null , incrementalDataRecords : [ ] } ;
952934 }
953935}
954936
@@ -1068,7 +1050,7 @@ function completeValue(
10681050
10691051 // If result value is null or undefined then return null.
10701052 if ( result == null ) {
1071- return { rawResult : null , incrementalDataRecords : undefined } ;
1053+ return { rawResult : null , incrementalDataRecords : [ ] } ;
10721054 }
10731055
10741056 // If field type is List, complete each item in the list with the inner type
@@ -1090,7 +1072,7 @@ function completeValue(
10901072 if ( isLeafType ( returnType ) ) {
10911073 return {
10921074 rawResult : completeLeafValue ( returnType , result ) ,
1093- incrementalDataRecords : undefined ,
1075+ incrementalDataRecords : [ ] ,
10941076 } ;
10951077 }
10961078
@@ -1169,7 +1151,7 @@ async function completePromisedValue(
11691151 path ,
11701152 incrementalContext ,
11711153 ) ;
1172- return { rawResult : null , incrementalDataRecords : undefined } ;
1154+ return { rawResult : null , incrementalDataRecords : [ ] } ;
11731155 }
11741156}
11751157
@@ -1269,7 +1251,7 @@ async function completeAsyncIteratorValue(
12691251 const completedResults : Array < unknown > = [ ] ;
12701252 const graphqlWrappedResult : GraphQLWrappedResult < Array < unknown > > = {
12711253 rawResult : completedResults ,
1272- incrementalDataRecords : undefined ,
1254+ incrementalDataRecords : [ ] ,
12731255 } ;
12741256 let index = 0 ;
12751257 const streamUsage = getStreamUsage (
@@ -1312,7 +1294,7 @@ async function completeAsyncIteratorValue(
13121294 exeContext . cancellableStreams . add ( streamRecord ) ;
13131295 }
13141296
1315- addIncrementalDataRecords ( graphqlWrappedResult , [ streamRecord ] ) ;
1297+ graphqlWrappedResult . incrementalDataRecords . push ( streamRecord ) ;
13161298 break ;
13171299 }
13181300
@@ -1462,7 +1444,7 @@ function completeIterableValue(
14621444 const completedResults : Array < unknown > = [ ] ;
14631445 const graphqlWrappedResult : GraphQLWrappedResult < Array < unknown > > = {
14641446 rawResult : completedResults ,
1465- incrementalDataRecords : undefined ,
1447+ incrementalDataRecords : [ ] ,
14661448 } ;
14671449 let index = 0 ;
14681450 const streamUsage = getStreamUsage (
@@ -1491,7 +1473,7 @@ function completeIterableValue(
14911473 ) ,
14921474 } ;
14931475
1494- addIncrementalDataRecords ( graphqlWrappedResult , [ syncStreamRecord ] ) ;
1476+ graphqlWrappedResult . incrementalDataRecords . push ( syncStreamRecord ) ;
14951477 break ;
14961478 }
14971479
@@ -1578,7 +1560,9 @@ function completeListItemValue(
15781560 completedResults . push (
15791561 completedItem . then (
15801562 ( resolved ) => {
1581- addIncrementalDataRecords ( parent , resolved . incrementalDataRecords ) ;
1563+ parent . incrementalDataRecords . push (
1564+ ...resolved . incrementalDataRecords ,
1565+ ) ;
15821566 return resolved . rawResult ;
15831567 } ,
15841568 ( rawError : unknown ) => {
@@ -1598,7 +1582,7 @@ function completeListItemValue(
15981582 }
15991583
16001584 completedResults . push ( completedItem . rawResult ) ;
1601- addIncrementalDataRecords ( parent , completedItem . incrementalDataRecords ) ;
1585+ parent . incrementalDataRecords . push ( ... completedItem . incrementalDataRecords ) ;
16021586 } catch ( rawError ) {
16031587 handleFieldError (
16041588 rawError ,
@@ -1643,7 +1627,7 @@ async function completePromisedListItemValue(
16431627 if ( isPromise ( completed ) ) {
16441628 completed = await completed ;
16451629 }
1646- addIncrementalDataRecords ( parent , completed . incrementalDataRecords ) ;
1630+ parent . incrementalDataRecords . push ( ... completed . incrementalDataRecords ) ;
16471631 return completed . rawResult ;
16481632 } catch ( rawError ) {
16491633 handleFieldError (
@@ -2748,7 +2732,7 @@ function completeStreamItem(
27482732 itemPath ,
27492733 incrementalContext ,
27502734 ) ;
2751- result = { rawResult : null , incrementalDataRecords : undefined } ;
2735+ result = { rawResult : null , incrementalDataRecords : [ ] } ;
27522736 }
27532737 } catch ( error ) {
27542738 incrementalContext . completed = true ;
@@ -2768,7 +2752,7 @@ function completeStreamItem(
27682752 itemPath ,
27692753 incrementalContext ,
27702754 ) ;
2771- return { rawResult : null , incrementalDataRecords : undefined } ;
2755+ return { rawResult : null , incrementalDataRecords : [ ] } ;
27722756 } )
27732757 . then (
27742758 ( resolvedItem ) => {
0 commit comments