@@ -174,7 +174,7 @@ export interface FormattedCompletedResult {
174174export function buildIncrementalResponse (
175175 context : IncrementalPublisherContext ,
176176 result : ObjMap < unknown > ,
177- errors : ReadonlyArray < GraphQLError > ,
177+ errors : ReadonlyArray < GraphQLError > | undefined ,
178178 incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ,
179179) : ExperimentalIncrementalExecutionResults {
180180 const incrementalPublisher = new IncrementalPublisher ( context ) ;
@@ -186,7 +186,7 @@ export function buildIncrementalResponse(
186186}
187187
188188interface IncrementalPublisherContext {
189- cancellableStreams : Set < StreamRecord > ;
189+ cancellableStreams ? : Set < StreamRecord > | undefined ;
190190}
191191
192192/**
@@ -220,7 +220,7 @@ class IncrementalPublisher {
220220
221221 buildResponse (
222222 data : ObjMap < unknown > ,
223- errors : ReadonlyArray < GraphQLError > ,
223+ errors : ReadonlyArray < GraphQLError > | undefined ,
224224 incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ,
225225 ) : ExperimentalIncrementalExecutionResults {
226226 this . _addIncrementalDataRecords ( incrementalDataRecords ) ;
@@ -229,7 +229,7 @@ class IncrementalPublisher {
229229 const pending = this . _pendingSourcesToResults ( ) ;
230230
231231 const initialResult : InitialIncrementalExecutionResult =
232- errors . length === 0
232+ errors === undefined
233233 ? { data, pending, hasNext : true }
234234 : { errors, data, pending, hasNext : true } ;
235235
@@ -441,8 +441,12 @@ class IncrementalPublisher {
441441 } ;
442442
443443 const returnStreamIterators = async ( ) : Promise < void > => {
444+ const cancellableStreams = this . _context . cancellableStreams ;
445+ if ( cancellableStreams === undefined ) {
446+ return ;
447+ }
444448 const promises : Array < Promise < unknown > > = [ ] ;
445- for ( const streamRecord of this . _context . cancellableStreams ) {
449+ for ( const streamRecord of cancellableStreams ) {
446450 if ( streamRecord . earlyReturn !== undefined ) {
447451 promises . push ( streamRecord . earlyReturn ( ) ) ;
448452 }
@@ -516,7 +520,7 @@ class IncrementalPublisher {
516520 ) ;
517521 }
518522
519- if ( deferredGroupedFieldSetResult . incrementalDataRecords . length > 0 ) {
523+ if ( deferredGroupedFieldSetResult . incrementalDataRecords !== undefined ) {
520524 this . _addIncrementalDataRecords (
521525 deferredGroupedFieldSetResult . incrementalDataRecords ,
522526 ) ;
@@ -586,14 +590,20 @@ class IncrementalPublisher {
586590 if ( streamItemsResult . result === undefined ) {
587591 this . _completed . push ( { id } ) ;
588592 this . _pending . delete ( streamRecord ) ;
589- this . _context . cancellableStreams . delete ( streamRecord ) ;
593+ const cancellableStreams = this . _context . cancellableStreams ;
594+ if ( cancellableStreams !== undefined ) {
595+ cancellableStreams . delete ( streamRecord ) ;
596+ }
590597 } else if ( streamItemsResult . result === null ) {
591598 this . _completed . push ( {
592599 id,
593600 errors : streamItemsResult . errors ,
594601 } ) ;
595602 this . _pending . delete ( streamRecord ) ;
596- this . _context . cancellableStreams . delete ( streamRecord ) ;
603+ const cancellableStreams = this . _context . cancellableStreams ;
604+ if ( cancellableStreams !== undefined ) {
605+ cancellableStreams . delete ( streamRecord ) ;
606+ }
597607 streamRecord . earlyReturn ?.( ) . catch ( ( ) => {
598608 /* c8 ignore next 1 */
599609 // ignore error
@@ -606,7 +616,7 @@ class IncrementalPublisher {
606616
607617 this . _incremental . push ( incrementalEntry ) ;
608618
609- if ( streamItemsResult . incrementalDataRecords . length > 0 ) {
619+ if ( streamItemsResult . incrementalDataRecords !== undefined ) {
610620 this . _addIncrementalDataRecords (
611621 streamItemsResult . incrementalDataRecords ,
612622 ) ;
@@ -663,7 +673,7 @@ function isDeferredGroupedFieldSetRecord(
663673export interface IncrementalContext {
664674 deferUsageSet : DeferUsageSet | undefined ;
665675 path : Path | undefined ;
666- errors : Array < GraphQLError > ;
676+ errors ? : Array < GraphQLError > | undefined ;
667677}
668678
669679export type DeferredGroupedFieldSetResult =
@@ -680,7 +690,7 @@ interface ReconcilableDeferredGroupedFieldSetResult {
680690 deferredFragmentRecords : ReadonlyArray < DeferredFragmentRecord > ;
681691 path : Array < string | number > ;
682692 result : BareDeferredGroupedFieldSetResult ;
683- incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ;
693+ incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > | undefined ;
684694 sent ?: true | undefined ;
685695}
686696
@@ -718,7 +728,6 @@ export class DeferredGroupedFieldSetRecord {
718728 const incrementalContext : IncrementalContext = {
719729 deferUsageSet,
720730 path,
721- errors : [ ] ,
722731 } ;
723732
724733 for ( const deferredFragmentRecord of deferredFragmentRecords ) {
@@ -786,7 +795,7 @@ interface NonReconcilableStreamItemsResult {
786795interface NonTerminatingStreamItemsResult {
787796 streamRecord : StreamRecord ;
788797 result : BareStreamItemsResult ;
789- incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ;
798+ incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > | undefined ;
790799}
791800
792801interface TerminatingStreamItemsResult {
@@ -826,7 +835,6 @@ export class StreamItemsRecord {
826835 const incrementalContext : IncrementalContext = {
827836 deferUsageSet : undefined ,
828837 path : itemPath ,
829- errors : [ ] ,
830838 } ;
831839
832840 this . _result = executor ( incrementalContext ) ;
@@ -850,7 +858,7 @@ export class StreamItemsRecord {
850858 ? {
851859 ...result ,
852860 incrementalDataRecords :
853- result . incrementalDataRecords . length === 0
861+ result . incrementalDataRecords === undefined
854862 ? [ this . nextStreamItems ]
855863 : [ this . nextStreamItems , ...result . incrementalDataRecords ] ,
856864 }
0 commit comments