Skip to content

Commit

Permalink
refactor collectAndExecuteSubfields (#185)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Richard <rob@1stdibs.com>
  • Loading branch information
yaacovCR and robrichard authored Apr 19, 2024
1 parent 189b502 commit 4e5051a
Showing 1 changed file with 16 additions and 52 deletions.
68 changes: 16 additions & 52 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1588,64 +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;
let hasDefers = Boolean(deferMap) || Boolean(newDeferUsages.length);

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

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

const subFields = executeFields(
exeContext,
returnType,
result,
path,
groupedFieldSet,
incrementalContext,
deferMap,
);

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

return withNewDeferredGroupedFieldSets(
subFields,
newDeferredGroupedFieldSetRecords,
);
hasDefers = true;
}
return subFields;
}

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

const newDeferMap = addNewDeferredFragments(
newDeferUsages,
new Map(deferMap),
path,
);
if (hasDefers) {
newDeferMap = addNewDeferredFragments(
newDeferUsages,
new Map(deferMap),
path,
);
}

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

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

0 comments on commit 4e5051a

Please sign in to comment.