Skip to content

Commit

Permalink
refactor collectAndExecuteSubfields
Browse files Browse the repository at this point in the history
  • Loading branch information
robrichard committed Apr 18, 2024
1 parent 189b502 commit cf273ff
Showing 1 changed file with 15 additions and 52 deletions.
67 changes: 15 additions & 52 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1588,65 +1588,28 @@ function collectAndExecuteSubfields(
// Collect sub-fields to execute to complete this value.
const { groupedFieldSet: nonPartitionedGroupedFieldSet, newDeferUsages } =
collectSubfields(exeContext, returnType, fieldGroup);
let groupedFieldSet = nonPartitionedGroupedFieldSet;
let newGroupedFieldSets;
let newDeferMap = deferMap;

if (newDeferUsages.length === 0) {
if (deferMap === undefined) {
return executeFields(
exeContext,
returnType,
result,
path,
nonPartitionedGroupedFieldSet,
incrementalContext,
undefined,
);
}

const { groupedFieldSet, newGroupedFieldSets } = buildSubFieldPlan(
if (newDeferUsages.length || newDeferMap !== undefined) {
({ groupedFieldSet, newGroupedFieldSets } = buildSubFieldPlan(
nonPartitionedGroupedFieldSet,
incrementalContext?.deferUsageSet,
);
));
}

const subFields = executeFields(
exeContext,
returnType,
result,
if (
newDeferUsages.length ||
(newGroupedFieldSets && newGroupedFieldSets.size > 0)
) {
newDeferMap = addNewDeferredFragments(
newDeferUsages,
new Map(deferMap),
path,
groupedFieldSet,
incrementalContext,
deferMap,
);

if (newGroupedFieldSets.size > 0) {
const newDeferredGroupedFieldSetRecords = executeDeferredGroupedFieldSets(
exeContext,
returnType,
result,
path,
incrementalContext?.deferUsageSet,
newGroupedFieldSets,
deferMap,
);

return withNewDeferredGroupedFieldSets(
subFields,
newDeferredGroupedFieldSetRecords,
);
}
return subFields;
}

const { groupedFieldSet, newGroupedFieldSets } = buildSubFieldPlan(
nonPartitionedGroupedFieldSet,
incrementalContext?.deferUsageSet,
);

const newDeferMap = addNewDeferredFragments(
newDeferUsages,
new Map(deferMap),
path,
);

const subFields = executeFields(
exeContext,
returnType,
Expand All @@ -1657,7 +1620,7 @@ function collectAndExecuteSubfields(
newDeferMap,
);

if (newGroupedFieldSets.size > 0) {
if (newDeferMap && newGroupedFieldSets && newGroupedFieldSets.size > 0) {
const newDeferredGroupedFieldSetRecords = executeDeferredGroupedFieldSets(
exeContext,
returnType,
Expand Down

0 comments on commit cf273ff

Please sign in to comment.