Skip to content

Commit 314f6b8

Browse files
committed
introduce publish methods so that
this moves all logic about introducing/releasing/pushing into the payload itself
1 parent a6f7137 commit 314f6b8

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

src/execution/execute.ts

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ function executeDeferredFragment(
18251825
label,
18261826
path,
18271827
parentContext,
1828-
exeContext,
1828+
publisher: exeContext.publisher,
18291829
});
18301830

18311831
let promiseOrData;
@@ -1871,7 +1871,7 @@ function executeStreamField(
18711871
label,
18721872
path: itemPath,
18731873
parentContext,
1874-
exeContext,
1874+
publisher: exeContext.publisher,
18751875
});
18761876

18771877
if (isPromise(item)) {
@@ -2054,7 +2054,7 @@ async function executeStreamAsyncIterator(
20542054
path: itemPath,
20552055
parentContext: previousIncrementalDataRecord,
20562056
asyncIterator,
2057-
exeContext,
2057+
publisher: exeContext.publisher,
20582058
});
20592059

20602060
let iteration;
@@ -2179,11 +2179,7 @@ function getIncrementalResult(
21792179
for (const incrementalDataRecord of completedRecords) {
21802180
const incrementalResult: IncrementalResult = {};
21812181
for (const child of incrementalDataRecord.children) {
2182-
if (child.isCompleted) {
2183-
publisher.push(child);
2184-
} else {
2185-
publisher.introduce(child);
2186-
}
2182+
child.publish();
21872183
}
21882184
if (isStreamItemsRecord(incrementalDataRecord)) {
21892185
const items = incrementalDataRecord.items;
@@ -2239,23 +2235,30 @@ class DeferredFragmentRecord {
22392235
parentContext: IncrementalDataRecord | undefined;
22402236
children: Set<IncrementalDataRecord>;
22412237
isCompleted: boolean;
2242-
_exeContext: ExecutionContext;
2238+
_publisher: Publisher<
2239+
IncrementalDataRecord,
2240+
SubsequentIncrementalExecutionResult
2241+
>;
2242+
22432243
constructor(opts: {
22442244
label: string | undefined;
22452245
path: Path | undefined;
22462246
parentContext: IncrementalDataRecord | undefined;
2247-
exeContext: ExecutionContext;
2247+
publisher: Publisher<
2248+
IncrementalDataRecord,
2249+
SubsequentIncrementalExecutionResult
2250+
>;
22482251
}) {
22492252
this.type = 'defer';
22502253
this.label = opts.label;
22512254
this.path = pathToArray(opts.path);
22522255
this.parentContext = opts.parentContext;
22532256
this.errors = [];
2254-
this._exeContext = opts.exeContext;
2257+
this._publisher = opts.publisher;
22552258
if (this.parentContext) {
22562259
this.parentContext.children.add(this);
22572260
} else {
2258-
this._exeContext.publisher.introduce(this);
2261+
this._publisher.introduce(this);
22592262
}
22602263
this.children = new Set();
22612264
this.isCompleted = false;
@@ -2265,7 +2268,15 @@ class DeferredFragmentRecord {
22652268
addData(data: ObjMap<unknown> | null) {
22662269
this.data = data;
22672270
this.isCompleted = true;
2268-
this._exeContext.publisher.release(this);
2271+
this._publisher.release(this);
2272+
}
2273+
2274+
publish() {
2275+
if (this.isCompleted) {
2276+
this._publisher.push(this);
2277+
} else {
2278+
this._publisher.introduce(this);
2279+
}
22692280
}
22702281
}
22712282

@@ -2280,13 +2291,20 @@ class StreamItemsRecord {
22802291
asyncIterator: AsyncIterator<unknown> | undefined;
22812292
isCompletedAsyncIterator?: boolean;
22822293
isCompleted: boolean;
2283-
_exeContext: ExecutionContext;
2294+
_publisher: Publisher<
2295+
IncrementalDataRecord,
2296+
SubsequentIncrementalExecutionResult
2297+
>;
2298+
22842299
constructor(opts: {
22852300
label: string | undefined;
22862301
path: Path | undefined;
22872302
asyncIterator?: AsyncIterator<unknown>;
22882303
parentContext: IncrementalDataRecord | undefined;
2289-
exeContext: ExecutionContext;
2304+
publisher: Publisher<
2305+
IncrementalDataRecord,
2306+
SubsequentIncrementalExecutionResult
2307+
>;
22902308
}) {
22912309
this.type = 'stream';
22922310
this.items = null;
@@ -2295,11 +2313,11 @@ class StreamItemsRecord {
22952313
this.parentContext = opts.parentContext;
22962314
this.asyncIterator = opts.asyncIterator;
22972315
this.errors = [];
2298-
this._exeContext = opts.exeContext;
2316+
this._publisher = opts.publisher;
22992317
if (this.parentContext) {
23002318
this.parentContext.children.add(this);
23012319
} else {
2302-
this._exeContext.publisher.introduce(this);
2320+
this._publisher.introduce(this);
23032321
}
23042322
this.children = new Set();
23052323
this.isCompleted = false;
@@ -2309,12 +2327,20 @@ class StreamItemsRecord {
23092327
addItems(items: Array<unknown> | null) {
23102328
this.items = items;
23112329
this.isCompleted = true;
2312-
this._exeContext.publisher.release(this);
2330+
this._publisher.release(this);
23132331
}
23142332

23152333
setIsCompletedAsyncIterator() {
23162334
this.isCompletedAsyncIterator = true;
23172335
}
2336+
2337+
publish() {
2338+
if (this.isCompleted) {
2339+
this._publisher.push(this);
2340+
} else {
2341+
this._publisher.introduce(this);
2342+
}
2343+
}
23182344
}
23192345

23202346
type IncrementalDataRecord = DeferredFragmentRecord | StreamItemsRecord;

0 commit comments

Comments
 (0)