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

create new deferred grouped field set records lazily #3998

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
80 changes: 35 additions & 45 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,6 @@ function executeOperation(

const path = undefined;

const newDeferredGroupedFieldSetRecords = addNewDeferredGroupedFieldSets(
incrementalPublisher,
newGroupedFieldSetDetailsMap,
newDeferMap,
path,
);

let result;
switch (operation.operation) {
case OperationTypeNode.QUERY:
Expand Down Expand Up @@ -476,7 +469,7 @@ function executeOperation(
rootType,
rootValue,
path,
newDeferredGroupedFieldSetRecords,
newGroupedFieldSetDetailsMap,
newDeferMap,
);

Expand Down Expand Up @@ -1501,36 +1494,28 @@ function deferredFragmentRecordFromDeferUsage(
return deferMap.get(deferUsage)!;
}

function addNewDeferredGroupedFieldSets(
function addNewDeferredGroupedFieldSet(
incrementalPublisher: IncrementalPublisher,
newGroupedFieldSetDetailsMap: Map<DeferUsageSet, NewGroupedFieldSetDetails>,
deferUsageSet: DeferUsageSet,
groupedFieldSet: GroupedFieldSet,
shouldInitiateDefer: boolean,
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord>,
path?: Path | undefined,
): ReadonlyArray<DeferredGroupedFieldSetRecord> {
const newDeferredGroupedFieldSetRecords: Array<DeferredGroupedFieldSetRecord> =
[];

for (const [
): DeferredGroupedFieldSetRecord {
const deferredFragmentRecords = getDeferredFragmentRecords(
deferUsageSet,
{ groupedFieldSet, shouldInitiateDefer },
] of newGroupedFieldSetDetailsMap) {
const deferredFragmentRecords = getDeferredFragmentRecords(
deferUsageSet,
deferMap,
);
const deferredGroupedFieldSetRecord = new DeferredGroupedFieldSetRecord({
path,
deferredFragmentRecords,
groupedFieldSet,
shouldInitiateDefer,
});
incrementalPublisher.reportNewDeferredGroupedFieldSetRecord(
deferredGroupedFieldSetRecord,
);
newDeferredGroupedFieldSetRecords.push(deferredGroupedFieldSetRecord);
}

return newDeferredGroupedFieldSetRecords;
deferMap,
);
const deferredGroupedFieldSetRecord = new DeferredGroupedFieldSetRecord({
path,
deferredFragmentRecords,
groupedFieldSet,
shouldInitiateDefer,
});
incrementalPublisher.reportNewDeferredGroupedFieldSetRecord(
deferredGroupedFieldSetRecord,
);
return deferredGroupedFieldSetRecord;
}

function getDeferredFragmentRecords(
Expand Down Expand Up @@ -1565,13 +1550,6 @@ function collectAndExecuteSubfields(
path,
);

const newDeferredGroupedFieldSetRecords = addNewDeferredGroupedFieldSets(
incrementalPublisher,
newGroupedFieldSetDetailsMap,
newDeferMap,
path,
);

const subFields = executeFields(
exeContext,
returnType,
Expand All @@ -1587,7 +1565,7 @@ function collectAndExecuteSubfields(
returnType,
result,
path,
newDeferredGroupedFieldSetRecords,
newGroupedFieldSetDetailsMap,
newDeferMap,
);

Expand Down Expand Up @@ -1891,11 +1869,23 @@ function executeDeferredGroupedFieldSets(
parentType: GraphQLObjectType,
sourceValue: unknown,
path: Path | undefined,
newDeferredGroupedFieldSetRecords: ReadonlyArray<DeferredGroupedFieldSetRecord>,
newGroupedFieldSetDetailsMap: Map<DeferUsageSet, NewGroupedFieldSetDetails>,
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord>,
): void {
for (const deferredGroupedFieldSetRecord of newDeferredGroupedFieldSetRecords) {
if (deferredGroupedFieldSetRecord.shouldInitiateDefer) {
for (const [
deferUsageSet,
{ groupedFieldSet, shouldInitiateDefer },
] of newGroupedFieldSetDetailsMap) {
const deferredGroupedFieldSetRecord = addNewDeferredGroupedFieldSet(
exeContext.incrementalPublisher,
deferUsageSet,
groupedFieldSet,
shouldInitiateDefer,
deferMap,
path,
);

if (shouldInitiateDefer) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
Promise.resolve().then(() =>
executeDeferredGroupedFieldSet(
Expand Down
Loading