From 0c05f3261b9c2d8b4538c474627ae5ca4df259cc Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Wed, 19 Jun 2024 22:39:01 +0300 Subject: [PATCH] f --- src/execution/IncrementalGraph.ts | 49 ++++++++++++++++--------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/execution/IncrementalGraph.ts b/src/execution/IncrementalGraph.ts index e6f7df24f7b..3e55b3587af 100644 --- a/src/execution/IncrementalGraph.ts +++ b/src/execution/IncrementalGraph.ts @@ -36,7 +36,7 @@ type SubsequentResultNode = DeferredFragmentNode | StreamRecord; * @internal */ export class IncrementalGraph { - private _pending: Set; + private _rootNodes: Set; private _deferredFragmentNodes: Map< DeferredFragmentRecord, DeferredFragmentNode @@ -48,7 +48,7 @@ export class IncrementalGraph { >; constructor() { - this._pending = new Set(); + this._rootNodes = new Set(); this._deferredFragmentNodes = new Map(); this._completedQueue = []; this._nextQueue = []; @@ -57,13 +57,13 @@ export class IncrementalGraph { getNewPending( incrementalDataRecords: ReadonlyArray, ): ReadonlyArray { - const newPending = new Set(); + const initialResultChildren = new Set(); this._addIncrementalDataRecords( incrementalDataRecords, undefined, - newPending, + initialResultChildren, ); - return this._pendingNodesToResults(newPending); + return this._promoteNonEmptyToRoot(initialResultChildren); } addCompletedReconcilableDeferredGroupedFieldSet( @@ -122,7 +122,7 @@ export class IncrementalGraph { } hasNext(): boolean { - return this._pending.size > 0; + return this._rootNodes.size > 0; } completeDeferredFragment(deferredFragmentRecord: DeferredFragmentRecord): @@ -137,7 +137,7 @@ export class IncrementalGraph { // TODO: add test case? /* c8 ignore next 3 */ if (deferredFragmentNode === undefined) { - return undefined; + return; } if (deferredFragmentNode.deferredGroupedFieldSetRecords.size > 0) { return; @@ -156,7 +156,7 @@ export class IncrementalGraph { ); } } - const newPending = this._pendingNodesToResults( + const newPending = this._promoteNonEmptyToRoot( deferredFragmentNode.children, ); return { newPending, reconcilableResults }; @@ -188,8 +188,8 @@ export class IncrementalGraph { } private _removePending(subsequentResultNode: SubsequentResultNode): void { - this._pending.delete(subsequentResultNode); - if (this._pending.size === 0) { + this._rootNodes.delete(subsequentResultNode); + if (this._rootNodes.size === 0) { for (const resolve of this._nextQueue) { resolve({ value: undefined, done: true }); } @@ -199,14 +199,14 @@ export class IncrementalGraph { private _addIncrementalDataRecords( incrementalDataRecords: ReadonlyArray, parents: ReadonlyArray | undefined, - newPending?: Set | undefined, + initialResultChildren?: Set | undefined, ): void { for (const incrementalDataRecord of incrementalDataRecords) { if (isDeferredGroupedFieldSetRecord(incrementalDataRecord)) { for (const deferredFragmentRecord of incrementalDataRecord.deferredFragmentRecords) { const deferredFragmentNode = this._addDeferredFragmentNode( deferredFragmentRecord, - newPending, + initialResultChildren, ); deferredFragmentNode.deferredGroupedFieldSetRecords.add( incrementalDataRecord, @@ -216,13 +216,13 @@ export class IncrementalGraph { this._onDeferredGroupedFieldSet(incrementalDataRecord); } } else if (parents === undefined) { - invariant(newPending !== undefined); - newPending.add(incrementalDataRecord); + invariant(initialResultChildren !== undefined); + initialResultChildren.add(incrementalDataRecord); } else { for (const parent of parents) { const deferredFragmentNode = this._addDeferredFragmentNode( parent, - newPending, + initialResultChildren, ); deferredFragmentNode.children.add(incrementalDataRecord); } @@ -230,7 +230,7 @@ export class IncrementalGraph { } } - private _pendingNodesToResults( + private _promoteNonEmptyToRoot( newPendingNodes: Set, ): ReadonlyArray { const newPendingResults: Array = []; @@ -242,7 +242,7 @@ export class IncrementalGraph { this._onDeferredGroupedFieldSet(deferredGroupedFieldSetRecord); } } - this._pending.add(node); + this._rootNodes.add(node); newPendingResults.push(node.deferredFragmentRecord); continue; } @@ -251,7 +251,7 @@ export class IncrementalGraph { newPendingNodes.add(child); } } else { - this._pending.add(node); + this._rootNodes.add(node); newPendingResults.push(node); // eslint-disable-next-line @typescript-eslint/no-floating-promises @@ -266,7 +266,7 @@ export class IncrementalGraph { ): boolean { return this._fragmentsToNodes( deferredGroupedFieldSetRecord.deferredFragmentRecords, - ).some((node) => this._pending.has(node)); + ).some((node) => this._rootNodes.has(node)); } private _fragmentsToNodes( @@ -281,7 +281,7 @@ export class IncrementalGraph { private _addDeferredFragmentNode( deferredFragmentRecord: DeferredFragmentRecord, - newPending: Set | undefined, + initialResultChildren: Set | undefined, ): DeferredFragmentNode { let deferredFragmentNode = this._deferredFragmentNodes.get( deferredFragmentRecord, @@ -301,11 +301,14 @@ export class IncrementalGraph { ); const parent = deferredFragmentRecord.parent; if (parent === undefined) { - invariant(newPending !== undefined); - newPending.add(deferredFragmentNode); + invariant(initialResultChildren !== undefined); + initialResultChildren.add(deferredFragmentNode); return deferredFragmentNode; } - const parentNode = this._addDeferredFragmentNode(parent, newPending); + const parentNode = this._addDeferredFragmentNode( + parent, + initialResultChildren, + ); parentNode.children.add(deferredFragmentNode); return deferredFragmentNode; }