@@ -174,7 +174,7 @@ export interface FormattedCompletedResult {
174
174
export function buildIncrementalResponse (
175
175
context : IncrementalPublisherContext ,
176
176
result : ObjMap < unknown > ,
177
- errors : ReadonlyArray < GraphQLError > ,
177
+ errors : ReadonlyArray < GraphQLError > | undefined ,
178
178
incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ,
179
179
) : ExperimentalIncrementalExecutionResults {
180
180
const incrementalPublisher = new IncrementalPublisher ( context ) ;
@@ -186,7 +186,7 @@ export function buildIncrementalResponse(
186
186
}
187
187
188
188
interface IncrementalPublisherContext {
189
- cancellableStreams : Set < StreamRecord > ;
189
+ cancellableStreams ? : Set < StreamRecord > | undefined ;
190
190
}
191
191
192
192
/**
@@ -220,7 +220,7 @@ class IncrementalPublisher {
220
220
221
221
buildResponse (
222
222
data : ObjMap < unknown > ,
223
- errors : ReadonlyArray < GraphQLError > ,
223
+ errors : ReadonlyArray < GraphQLError > | undefined ,
224
224
incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ,
225
225
) : ExperimentalIncrementalExecutionResults {
226
226
this . _addIncrementalDataRecords ( incrementalDataRecords ) ;
@@ -229,7 +229,7 @@ class IncrementalPublisher {
229
229
const pending = this . _pendingSourcesToResults ( ) ;
230
230
231
231
const initialResult : InitialIncrementalExecutionResult =
232
- errors . length === 0
232
+ errors === undefined
233
233
? { data, pending, hasNext : true }
234
234
: { errors, data, pending, hasNext : true } ;
235
235
@@ -441,8 +441,12 @@ class IncrementalPublisher {
441
441
} ;
442
442
443
443
const returnStreamIterators = async ( ) : Promise < void > => {
444
+ const cancellableStreams = this . _context . cancellableStreams ;
445
+ if ( cancellableStreams === undefined ) {
446
+ return ;
447
+ }
444
448
const promises : Array < Promise < unknown > > = [ ] ;
445
- for ( const streamRecord of this . _context . cancellableStreams ) {
449
+ for ( const streamRecord of cancellableStreams ) {
446
450
if ( streamRecord . earlyReturn !== undefined ) {
447
451
promises . push ( streamRecord . earlyReturn ( ) ) ;
448
452
}
@@ -516,7 +520,7 @@ class IncrementalPublisher {
516
520
) ;
517
521
}
518
522
519
- if ( deferredGroupedFieldSetResult . incrementalDataRecords . length > 0 ) {
523
+ if ( deferredGroupedFieldSetResult . incrementalDataRecords !== undefined ) {
520
524
this . _addIncrementalDataRecords (
521
525
deferredGroupedFieldSetResult . incrementalDataRecords ,
522
526
) ;
@@ -586,14 +590,20 @@ class IncrementalPublisher {
586
590
if ( streamItemsResult . result === undefined ) {
587
591
this . _completed . push ( { id } ) ;
588
592
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
+ }
590
597
} else if ( streamItemsResult . result === null ) {
591
598
this . _completed . push ( {
592
599
id,
593
600
errors : streamItemsResult . errors ,
594
601
} ) ;
595
602
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
+ }
597
607
streamRecord . earlyReturn ?.( ) . catch ( ( ) => {
598
608
/* c8 ignore next 1 */
599
609
// ignore error
@@ -606,7 +616,7 @@ class IncrementalPublisher {
606
616
607
617
this . _incremental . push ( incrementalEntry ) ;
608
618
609
- if ( streamItemsResult . incrementalDataRecords . length > 0 ) {
619
+ if ( streamItemsResult . incrementalDataRecords !== undefined ) {
610
620
this . _addIncrementalDataRecords (
611
621
streamItemsResult . incrementalDataRecords ,
612
622
) ;
@@ -663,7 +673,7 @@ function isDeferredGroupedFieldSetRecord(
663
673
export interface IncrementalContext {
664
674
deferUsageSet : DeferUsageSet | undefined ;
665
675
path : Path | undefined ;
666
- errors : Array < GraphQLError > ;
676
+ errors ? : Array < GraphQLError > | undefined ;
667
677
}
668
678
669
679
export type DeferredGroupedFieldSetResult =
@@ -680,7 +690,7 @@ interface ReconcilableDeferredGroupedFieldSetResult {
680
690
deferredFragmentRecords : ReadonlyArray < DeferredFragmentRecord > ;
681
691
path : Array < string | number > ;
682
692
result : BareDeferredGroupedFieldSetResult ;
683
- incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ;
693
+ incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > | undefined ;
684
694
sent ?: true | undefined ;
685
695
}
686
696
@@ -718,7 +728,6 @@ export class DeferredGroupedFieldSetRecord {
718
728
const incrementalContext : IncrementalContext = {
719
729
deferUsageSet,
720
730
path,
721
- errors : [ ] ,
722
731
} ;
723
732
724
733
for ( const deferredFragmentRecord of deferredFragmentRecords ) {
@@ -786,7 +795,7 @@ interface NonReconcilableStreamItemsResult {
786
795
interface NonTerminatingStreamItemsResult {
787
796
streamRecord : StreamRecord ;
788
797
result : BareStreamItemsResult ;
789
- incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > ;
798
+ incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > | undefined ;
790
799
}
791
800
792
801
interface TerminatingStreamItemsResult {
@@ -826,7 +835,6 @@ export class StreamItemsRecord {
826
835
const incrementalContext : IncrementalContext = {
827
836
deferUsageSet : undefined ,
828
837
path : itemPath ,
829
- errors : [ ] ,
830
838
} ;
831
839
832
840
this . _result = executor ( incrementalContext ) ;
@@ -850,7 +858,7 @@ export class StreamItemsRecord {
850
858
? {
851
859
...result ,
852
860
incrementalDataRecords :
853
- result . incrementalDataRecords . length === 0
861
+ result . incrementalDataRecords === undefined
854
862
? [ this . nextStreamItems ]
855
863
: [ this . nextStreamItems , ...result . incrementalDataRecords ] ,
856
864
}
0 commit comments