@@ -307,6 +307,12 @@ export class IncrementalPublisher {
307307 path,
308308 deferredFragmentRecords,
309309 groupedFieldSet,
310+ priority :
311+ incrementalDataRecord === undefined
312+ ? 1
313+ : shouldInitiateDefer
314+ ? incrementalDataRecord . priority + 1
315+ : incrementalDataRecord . priority ,
310316 shouldInitiateDefer,
311317 } ) ;
312318 for ( const deferredFragmentRecord of deferredFragmentRecords ) {
@@ -345,6 +351,10 @@ export class IncrementalPublisher {
345351 const streamItemsRecord = new StreamItemsRecord ( {
346352 streamRecord,
347353 path,
354+ priority :
355+ incrementalDataRecord === undefined
356+ ? 1
357+ : incrementalDataRecord . priority + 1 ,
348358 parents,
349359 } ) ;
350360
@@ -672,13 +682,17 @@ export class IncrementalPublisher {
672682
673683 if ( isStreamItemsRecord ( subsequentResultRecord ) ) {
674684 this . _introduce ( subsequentResultRecord ) ;
685+ subsequentResultRecord . publish ( ) ;
675686 return ;
676687 }
677688
678689 if ( subsequentResultRecord . _pending . size === 0 ) {
679690 subsequentResultRecord . isCompleted = true ;
680691 this . _push ( subsequentResultRecord ) ;
681692 } else {
693+ for ( const deferredGroupedFieldSetRecord of subsequentResultRecord . deferredGroupedFieldSetRecords ) {
694+ deferredGroupedFieldSetRecord . publish ( ) ;
695+ }
682696 this . _introduce ( subsequentResultRecord ) ;
683697 }
684698 }
@@ -748,24 +762,38 @@ export class IncrementalPublisher {
748762/** @internal */
749763export class DeferredGroupedFieldSetRecord {
750764 path : ReadonlyArray < string | number > ;
765+ priority : number ;
751766 deferredFragmentRecords : ReadonlyArray < DeferredFragmentRecord > ;
752767 groupedFieldSet : GroupedFieldSet ;
753768 shouldInitiateDefer : boolean ;
754769 errors : Array < GraphQLError > ;
755770 data : ObjMap < unknown > | undefined ;
771+ published : true | Promise < void > ;
772+ publish : ( ) => void ;
756773 sent : boolean ;
757774
758775 constructor ( opts : {
759776 path : Path | undefined ;
777+ priority : number ;
760778 deferredFragmentRecords : ReadonlyArray < DeferredFragmentRecord > ;
761779 groupedFieldSet : GroupedFieldSet ;
762780 shouldInitiateDefer : boolean ;
763781 } ) {
764782 this . path = pathToArray ( opts . path ) ;
783+ this . priority = opts . priority ;
765784 this . deferredFragmentRecords = opts . deferredFragmentRecords ;
766785 this . groupedFieldSet = opts . groupedFieldSet ;
767786 this . shouldInitiateDefer = opts . shouldInitiateDefer ;
768787 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+ } ;
769797 this . sent = false ;
770798 }
771799}
@@ -822,26 +850,40 @@ export class StreamItemsRecord {
822850 errors : Array < GraphQLError > ;
823851 streamRecord : StreamRecord ;
824852 path : ReadonlyArray < string | number > ;
853+ priority : number ;
825854 items : Array < unknown > ;
826855 parents : ReadonlyArray < SubsequentResultRecord > | undefined ;
827856 children : Set < SubsequentResultRecord > ;
828857 isFinalRecord ?: boolean ;
829858 isCompletedAsyncIterator ?: boolean ;
830859 isCompleted : boolean ;
860+ published : true | Promise < void > ;
861+ publish : ( ) => void ;
831862 sent : boolean ;
832863
833864 constructor ( opts : {
834865 streamRecord : StreamRecord ;
835866 path : Path | undefined ;
867+ priority : number ;
836868 parents : ReadonlyArray < SubsequentResultRecord > | undefined ;
837869 } ) {
838870 this . streamRecord = opts . streamRecord ;
839871 this . path = pathToArray ( opts . path ) ;
872+ this . priority = opts . priority ;
840873 this . parents = opts . parents ;
841874 this . children = new Set ( ) ;
842875 this . errors = [ ] ;
843876 this . isCompleted = false ;
844877 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+ } ;
845887 this . sent = false ;
846888 }
847889}
0 commit comments