@@ -100,7 +100,8 @@ export interface IncrementalDeferResult<
100
100
> {
101
101
errors ?: ReadonlyArray < GraphQLError > ;
102
102
data : TData ;
103
- path ?: ReadonlyArray < string | number > ;
103
+ id ?: string ;
104
+ subPath ?: ReadonlyArray < string | number > ;
104
105
extensions ?: TExtensions ;
105
106
}
106
107
@@ -110,7 +111,8 @@ export interface FormattedIncrementalDeferResult<
110
111
> {
111
112
errors ?: ReadonlyArray < GraphQLFormattedError > ;
112
113
data : TData ;
113
- path ?: ReadonlyArray < string | number > ;
114
+ id ?: string ;
115
+ subPath ?: ReadonlyArray < string | number > ;
114
116
extensions ?: TExtensions ;
115
117
}
116
118
@@ -120,7 +122,8 @@ export interface IncrementalStreamResult<
120
122
> {
121
123
errors ?: ReadonlyArray < GraphQLError > ;
122
124
items : TData ;
123
- path ?: ReadonlyArray < string | number > ;
125
+ id ?: string ;
126
+ subPath ?: ReadonlyArray < string | number > ;
124
127
extensions ?: TExtensions ;
125
128
}
126
129
@@ -130,7 +133,8 @@ export interface FormattedIncrementalStreamResult<
130
133
> {
131
134
errors ?: ReadonlyArray < GraphQLFormattedError > ;
132
135
items : TData ;
133
- path ?: ReadonlyArray < string | number > ;
136
+ id ?: string ;
137
+ subPath ?: ReadonlyArray < string | number > ;
134
138
extensions ?: TExtensions ;
135
139
}
136
140
@@ -562,7 +566,8 @@ export class IncrementalPublisher {
562
566
}
563
567
const incrementalResult : IncrementalStreamResult = {
564
568
items : subsequentResultRecord . items ,
565
- path : subsequentResultRecord . streamRecord . path ,
569
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
570
+ id : subsequentResultRecord . streamRecord . id ! ,
566
571
} ;
567
572
if ( subsequentResultRecord . errors . length > 0 ) {
568
573
incrementalResult . errors = subsequentResultRecord . errors ;
@@ -579,11 +584,8 @@ export class IncrementalPublisher {
579
584
for ( const deferredGroupedFieldSetRecord of subsequentResultRecord . deferredGroupedFieldSetRecords ) {
580
585
if ( ! deferredGroupedFieldSetRecord . sent ) {
581
586
deferredGroupedFieldSetRecord . sent = true ;
582
- const incrementalResult : IncrementalDeferResult = {
583
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
584
- data : deferredGroupedFieldSetRecord . data ! ,
585
- path : deferredGroupedFieldSetRecord . path ,
586
- } ;
587
+ const incrementalResult : IncrementalDeferResult =
588
+ this . _getIncrementalDeferResult ( deferredGroupedFieldSetRecord ) ;
587
589
if ( deferredGroupedFieldSetRecord . errors . length > 0 ) {
588
590
incrementalResult . errors = deferredGroupedFieldSetRecord . errors ;
589
591
}
@@ -600,6 +602,40 @@ export class IncrementalPublisher {
600
602
} ;
601
603
}
602
604
605
+ private _getIncrementalDeferResult (
606
+ deferredGroupedFieldSetRecord : DeferredGroupedFieldSetRecord ,
607
+ ) : IncrementalDeferResult {
608
+ const { data, deferredFragmentRecords } = deferredGroupedFieldSetRecord ;
609
+ let maxLength = deferredFragmentRecords [ 0 ] . path . length ;
610
+ let maxIndex = 0 ;
611
+ for ( let i = 1 ; i < deferredFragmentRecords . length ; i ++ ) {
612
+ const deferredFragmentRecord = deferredFragmentRecords [ i ] ;
613
+ const length = deferredFragmentRecord . path . length ;
614
+ if ( length > maxLength ) {
615
+ maxLength = length ;
616
+ maxIndex = i ;
617
+ }
618
+ }
619
+ const recordWithLongestPath = deferredFragmentRecords [ maxIndex ] ;
620
+ const longestPath = recordWithLongestPath . path ;
621
+ const subPath = deferredGroupedFieldSetRecord . path . slice (
622
+ longestPath . length ,
623
+ ) ;
624
+ const id = recordWithLongestPath . id ;
625
+ const incrementalDeferResult : IncrementalDeferResult = {
626
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
627
+ data : data ! ,
628
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
629
+ id : id ! ,
630
+ } ;
631
+
632
+ if ( subPath . length > 0 ) {
633
+ incrementalDeferResult . subPath = subPath ;
634
+ }
635
+
636
+ return incrementalDeferResult ;
637
+ }
638
+
603
639
private _completedRecordToResult (
604
640
completedRecord : DeferredFragmentRecord | StreamRecord ,
605
641
) : CompletedResult {
0 commit comments