Skip to content

Commit d4807a6

Browse files
authored
polish(IncrementalPublisher): introduce ensureId helper (#4502)
unifies setting at initial release vs. getting with invariant
1 parent f625c32 commit d4807a6

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/execution/IncrementalPublisher.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,16 @@ class IncrementalPublisher {
106106
};
107107
}
108108

109+
private _ensureId(deliveryGroup: DeliveryGroup): string {
110+
return (deliveryGroup.id ??= String(this._nextId++));
111+
}
112+
109113
private _toPendingResults(
110114
newRootNodes: ReadonlyArray<DeliveryGroup>,
111115
): Array<PendingResult> {
112116
const pendingResults: Array<PendingResult> = [];
113117
for (const node of newRootNodes) {
114-
const id = String(this._getNextId());
115-
node.id = id;
118+
const id = this._ensureId(node);
116119
const pendingResult: PendingResult = {
117120
id,
118121
path: pathToArray(node.path),
@@ -125,10 +128,6 @@ class IncrementalPublisher {
125128
return pendingResults;
126129
}
127130

128-
private _getNextId(): string {
129-
return String(this._nextId++);
130-
}
131-
132131
private _handleCompletedBatch(
133132
batch: Iterable<IncrementalDataRecordResult>,
134133
): SubsequentIncrementalExecutionResult | undefined {
@@ -185,8 +184,7 @@ class IncrementalPublisher {
185184
if (
186185
this._incrementalGraph.removeDeferredFragment(deferredFragmentRecord)
187186
) {
188-
const id = deferredFragmentRecord.id;
189-
invariant(id !== undefined);
187+
const id = this._ensureId(deferredFragmentRecord);
190188
context.completed.push({
191189
id,
192190
errors: completedExecutionGroup.errors,
@@ -208,8 +206,7 @@ class IncrementalPublisher {
208206
if (completion === undefined) {
209207
continue;
210208
}
211-
const id = deferredFragmentRecord.id;
212-
invariant(id !== undefined);
209+
const id = this._ensureId(deferredFragmentRecord);
213210
const incremental = context.incremental;
214211
const { newRootNodes, successfulExecutionGroups } = completion;
215212
context.pending.push(...this._toPendingResults(newRootNodes));
@@ -237,8 +234,7 @@ class IncrementalPublisher {
237234
context: SubsequentIncrementalExecutionResultContext,
238235
): void {
239236
const streamRecord = streamItemsResult.streamRecord;
240-
const id = streamRecord.id;
241-
invariant(id !== undefined);
237+
const id = this._ensureId(streamRecord);
242238
if (streamItemsResult.errors !== undefined) {
243239
context.completed.push({
244240
id,

0 commit comments

Comments
 (0)