Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(incremental): fix logic around selecting id/subPath #3988

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 12 additions & 15 deletions src/execution/IncrementalPublisher.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { invariant } from '../jsutils/invariant.js';
import type { ObjMap } from '../jsutils/ObjMap.js';
import type { Path } from '../jsutils/Path.js';
import { pathToArray } from '../jsutils/Path.js';
Expand Down Expand Up @@ -609,29 +610,25 @@ 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;
let id;
for (const deferredFragmentRecord of deferredFragmentRecords) {
if (deferredFragmentRecord.id === undefined) {
continue;
}
const length = deferredFragmentRecord.path.length;
if (length > maxLength) {
if (maxLength === undefined || length > maxLength) {
maxLength = length;
maxIndex = i;
id = deferredFragmentRecord.id;
}
}
const recordWithLongestPath = deferredFragmentRecords[maxIndex];
const longestPath = recordWithLongestPath.path;
const subPath = deferredGroupedFieldSetRecord.path.slice(
longestPath.length,
);
const id = recordWithLongestPath.id;
invariant(id != null, 'No id for deferred incremental result');
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
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: id!,
id,
};

if (subPath.length > 0) {
Expand Down
Loading