Skip to content

polish(incremental): remove id mutation #4107

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions src/execution/IncrementalPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ interface SubsequentIncrementalExecutionResultContext {
*/
class IncrementalPublisher {
private _context: IncrementalPublisherContext;
private _ids: Map<SubsequentResultRecord, string>;
private _nextId: number;
private _incrementalGraph: IncrementalGraph;

constructor(context: IncrementalPublisherContext) {
this._context = context;
this._ids = new Map();
this._nextId = 0;
this._incrementalGraph = new IncrementalGraph();
}
Expand Down Expand Up @@ -96,7 +98,7 @@ class IncrementalPublisher {
const pendingResults: Array<PendingResult> = [];
for (const pendingSource of newPending) {
const id = String(this._getNextId());
pendingSource.id = id;
this._ids.set(pendingSource, id);
const pendingResult: PendingResult = {
id,
path: pathToArray(pendingSource.path),
Expand Down Expand Up @@ -232,14 +234,15 @@ class IncrementalPublisher {
) {
for (const deferredFragmentRecord of deferredGroupedFieldSetResult
.deferredGroupedFieldSetRecord.deferredFragmentRecords) {
const id = deferredFragmentRecord.id;
if (
!this._incrementalGraph.removeDeferredFragment(deferredFragmentRecord)
) {
// This can occur if multiple deferred grouped field sets error for a fragment.
continue;
}
const id = this._ids.get(deferredFragmentRecord);
invariant(id !== undefined);
this._ids.delete(deferredFragmentRecord);
context.completed.push({
id,
errors: deferredGroupedFieldSetResult.errors,
Expand All @@ -265,7 +268,7 @@ class IncrementalPublisher {
if (reconcilableResults === undefined) {
continue;
}
const id = deferredFragmentRecord.id;
const id = this._ids.get(deferredFragmentRecord);
invariant(id !== undefined);
const incremental = context.incremental;
for (const reconcilableResult of reconcilableResults) {
Expand All @@ -283,6 +286,7 @@ class IncrementalPublisher {
}
incremental.push(incrementalEntry);
}
this._ids.delete(deferredFragmentRecord);
context.completed.push({ id });
}
}
Expand All @@ -292,9 +296,10 @@ class IncrementalPublisher {
context: SubsequentIncrementalExecutionResultContext,
): void {
const streamRecord = streamItemsResult.streamRecord;
const id = streamRecord.id;
const id = this._ids.get(streamRecord);
invariant(id !== undefined);
if (streamItemsResult.errors !== undefined) {
this._ids.delete(streamRecord);
context.completed.push({
id,
errors: streamItemsResult.errors,
Expand All @@ -309,6 +314,7 @@ class IncrementalPublisher {
});
}
} else if (streamItemsResult.result === undefined) {
this._ids.delete(streamRecord);
context.completed.push({ id });
this._incrementalGraph.removeStream(streamRecord);
if (isCancellableStreamRecord(streamRecord)) {
Expand Down Expand Up @@ -344,7 +350,7 @@ class IncrementalPublisher {
if (deferredFragmentRecord === initialDeferredFragmentRecord) {
continue;
}
const id = deferredFragmentRecord.id;
const id = this._ids.get(deferredFragmentRecord);
// TODO: add test case for when an fragment has not been released, but might be processed for the shortest path.
/* c8 ignore next 3 */
if (id === undefined) {
Expand Down
2 changes: 0 additions & 2 deletions src/execution/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ export type SubsequentResultRecord = DeferredFragmentRecord | StreamRecord;
export interface DeferredFragmentRecord {
path: Path | undefined;
label: string | undefined;
id?: string | undefined;
parent: DeferredFragmentRecord | undefined;
}

Expand All @@ -232,7 +231,6 @@ export type StreamItemRecord = ThunkIncrementalResult<StreamItemResult>;
export interface StreamRecord {
path: Path;
label: string | undefined;
id?: string | undefined;
streamItemQueue: Array<StreamItemRecord>;
}

Expand Down
Loading