@@ -307,6 +307,12 @@ export class IncrementalPublisher {
307
307
path,
308
308
deferredFragmentRecords,
309
309
groupedFieldSet,
310
+ priority :
311
+ incrementalDataRecord === undefined
312
+ ? 1
313
+ : shouldInitiateDefer
314
+ ? incrementalDataRecord . priority + 1
315
+ : incrementalDataRecord . priority ,
310
316
shouldInitiateDefer,
311
317
} ) ;
312
318
for ( const deferredFragmentRecord of deferredFragmentRecords ) {
@@ -345,6 +351,10 @@ export class IncrementalPublisher {
345
351
const streamItemsRecord = new StreamItemsRecord ( {
346
352
streamRecord,
347
353
path,
354
+ priority :
355
+ incrementalDataRecord === undefined
356
+ ? 1
357
+ : incrementalDataRecord . priority + 1 ,
348
358
parents,
349
359
} ) ;
350
360
@@ -672,13 +682,17 @@ export class IncrementalPublisher {
672
682
673
683
if ( isStreamItemsRecord ( subsequentResultRecord ) ) {
674
684
this . _introduce ( subsequentResultRecord ) ;
685
+ subsequentResultRecord . publish ( ) ;
675
686
return ;
676
687
}
677
688
678
689
if ( subsequentResultRecord . _pending . size === 0 ) {
679
690
subsequentResultRecord . isCompleted = true ;
680
691
this . _push ( subsequentResultRecord ) ;
681
692
} else {
693
+ for ( const deferredGroupedFieldSetRecord of subsequentResultRecord . deferredGroupedFieldSetRecords ) {
694
+ deferredGroupedFieldSetRecord . publish ( ) ;
695
+ }
682
696
this . _introduce ( subsequentResultRecord ) ;
683
697
}
684
698
}
@@ -748,24 +762,38 @@ export class IncrementalPublisher {
748
762
/** @internal */
749
763
export class DeferredGroupedFieldSetRecord {
750
764
path : ReadonlyArray < string | number > ;
765
+ priority : number ;
751
766
deferredFragmentRecords : ReadonlyArray < DeferredFragmentRecord > ;
752
767
groupedFieldSet : GroupedFieldSet ;
753
768
shouldInitiateDefer : boolean ;
754
769
errors : Array < GraphQLError > ;
755
770
data : ObjMap < unknown > | undefined ;
771
+ published : true | Promise < void > ;
772
+ publish : ( ) => void ;
756
773
sent : boolean ;
757
774
758
775
constructor ( opts : {
759
776
path : Path | undefined ;
777
+ priority : number ;
760
778
deferredFragmentRecords : ReadonlyArray < DeferredFragmentRecord > ;
761
779
groupedFieldSet : GroupedFieldSet ;
762
780
shouldInitiateDefer : boolean ;
763
781
} ) {
764
782
this . path = pathToArray ( opts . path ) ;
783
+ this . priority = opts . priority ;
765
784
this . deferredFragmentRecords = opts . deferredFragmentRecords ;
766
785
this . groupedFieldSet = opts . groupedFieldSet ;
767
786
this . shouldInitiateDefer = opts . shouldInitiateDefer ;
768
787
this . errors = [ ] ;
788
+ // promiseWithResolvers uses void only as a generic type parameter
789
+ // see: https://typescript-eslint.io/rules/no-invalid-void-type/
790
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
791
+ const { promise : published , resolve } = promiseWithResolvers < void > ( ) ;
792
+ this . published = published ;
793
+ this . publish = ( ) => {
794
+ resolve ( ) ;
795
+ this . published = true ;
796
+ } ;
769
797
this . sent = false ;
770
798
}
771
799
}
@@ -822,26 +850,40 @@ export class StreamItemsRecord {
822
850
errors : Array < GraphQLError > ;
823
851
streamRecord : StreamRecord ;
824
852
path : ReadonlyArray < string | number > ;
853
+ priority : number ;
825
854
items : Array < unknown > ;
826
855
parents : ReadonlyArray < SubsequentResultRecord > | undefined ;
827
856
children : Set < SubsequentResultRecord > ;
828
857
isFinalRecord ?: boolean ;
829
858
isCompletedAsyncIterator ?: boolean ;
830
859
isCompleted : boolean ;
860
+ published : true | Promise < void > ;
861
+ publish : ( ) => void ;
831
862
sent : boolean ;
832
863
833
864
constructor ( opts : {
834
865
streamRecord : StreamRecord ;
835
866
path : Path | undefined ;
867
+ priority : number ;
836
868
parents : ReadonlyArray < SubsequentResultRecord > | undefined ;
837
869
} ) {
838
870
this . streamRecord = opts . streamRecord ;
839
871
this . path = pathToArray ( opts . path ) ;
872
+ this . priority = opts . priority ;
840
873
this . parents = opts . parents ;
841
874
this . children = new Set ( ) ;
842
875
this . errors = [ ] ;
843
876
this . isCompleted = false ;
844
877
this . items = [ ] ;
878
+ // promiseWithResolvers uses void only as a generic type parameter
879
+ // see: https://typescript-eslint.io/rules/no-invalid-void-type/
880
+ // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
881
+ const { promise : published , resolve } = promiseWithResolvers < void > ( ) ;
882
+ this . published = published ;
883
+ this . publish = ( ) => {
884
+ resolve ( ) ;
885
+ this . published = true ;
886
+ } ;
845
887
this . sent = false ;
846
888
}
847
889
}
0 commit comments