Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/execution/IncrementalPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,29 +609,29 @@ export class IncrementalPublisher {
deferredGroupedFieldSetRecord: DeferredGroupedFieldSetRecord,
): IncrementalDeferResult {
const { data, deferredFragmentRecords } = deferredGroupedFieldSetRecord;
let maxLength = deferredFragmentRecords[0].path.length;
let maxIndex = 0;
for (let i = 1; i < deferredFragmentRecords.length; i++) {
const deferredFragmentRecord = deferredFragmentRecords[i];
let maxLength: number | undefined;
let idWithLongestPath: string | undefined;
for (const deferredFragmentRecord of deferredFragmentRecords) {
const id = deferredFragmentRecord.id;
if (id === undefined) {
continue;
}
const length = deferredFragmentRecord.path.length;
if (length > maxLength) {
if (maxLength === undefined || length > maxLength) {
maxLength = length;
maxIndex = i;
idWithLongestPath = id;
}
}
const recordWithLongestPath = deferredFragmentRecords[maxIndex];
const longestPath = recordWithLongestPath.path;
const subPath = deferredGroupedFieldSetRecord.path.slice(
longestPath.length,
);
const id = recordWithLongestPath.id;
const subPath = deferredGroupedFieldSetRecord.path.slice(maxLength);
const incrementalDeferResult: IncrementalDeferResult = {
// safe because `data``is always defined when the record is completed
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
data: data!,
// safe because `id` is defined once the fragment has been released as pending
// safe because `id` is always defined once the fragment has been released
// as pending and at least one fragment has been completed, so must have been
// released as pending
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: id!,
id: idWithLongestPath!,
};

if (subPath.length > 0) {
Expand Down