Skip to content

Commit de2f590

Browse files
committed
refactor collectAndExecuteSubfields
1 parent 189b502 commit de2f590

1 file changed

Lines changed: 16 additions & 52 deletions

File tree

src/execution/execute.ts

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,64 +1588,28 @@ function collectAndExecuteSubfields(
15881588
// Collect sub-fields to execute to complete this value.
15891589
const { groupedFieldSet: nonPartitionedGroupedFieldSet, newDeferUsages } =
15901590
collectSubfields(exeContext, returnType, fieldGroup);
1591+
let groupedFieldSet = nonPartitionedGroupedFieldSet;
1592+
let newGroupedFieldSets;
1593+
let newDeferMap = deferMap;
1594+
let hasDefers = Boolean(deferMap) || Boolean(newDeferUsages.length);
15911595

1592-
if (newDeferUsages.length === 0) {
1593-
if (deferMap === undefined) {
1594-
return executeFields(
1595-
exeContext,
1596-
returnType,
1597-
result,
1598-
path,
1599-
nonPartitionedGroupedFieldSet,
1600-
incrementalContext,
1601-
undefined,
1602-
);
1603-
}
1604-
1605-
const { groupedFieldSet, newGroupedFieldSets } = buildSubFieldPlan(
1596+
if (hasDefers) {
1597+
({ groupedFieldSet, newGroupedFieldSets } = buildSubFieldPlan(
16061598
nonPartitionedGroupedFieldSet,
16071599
incrementalContext?.deferUsageSet,
1608-
);
1609-
1610-
const subFields = executeFields(
1611-
exeContext,
1612-
returnType,
1613-
result,
1614-
path,
1615-
groupedFieldSet,
1616-
incrementalContext,
1617-
deferMap,
1618-
);
1619-
1600+
));
16201601
if (newGroupedFieldSets.size > 0) {
1621-
const newDeferredGroupedFieldSetRecords = executeDeferredGroupedFieldSets(
1622-
exeContext,
1623-
returnType,
1624-
result,
1625-
path,
1626-
incrementalContext?.deferUsageSet,
1627-
newGroupedFieldSets,
1628-
deferMap,
1629-
);
1630-
1631-
return withNewDeferredGroupedFieldSets(
1632-
subFields,
1633-
newDeferredGroupedFieldSetRecords,
1634-
);
1602+
hasDefers = true;
16351603
}
1636-
return subFields;
16371604
}
16381605

1639-
const { groupedFieldSet, newGroupedFieldSets } = buildSubFieldPlan(
1640-
nonPartitionedGroupedFieldSet,
1641-
incrementalContext?.deferUsageSet,
1642-
);
1643-
1644-
const newDeferMap = addNewDeferredFragments(
1645-
newDeferUsages,
1646-
new Map(deferMap),
1647-
path,
1648-
);
1606+
if (hasDefers) {
1607+
newDeferMap = addNewDeferredFragments(
1608+
newDeferUsages,
1609+
new Map(deferMap),
1610+
path,
1611+
);
1612+
}
16491613

16501614
const subFields = executeFields(
16511615
exeContext,
@@ -1657,7 +1621,7 @@ function collectAndExecuteSubfields(
16571621
newDeferMap,
16581622
);
16591623

1660-
if (newGroupedFieldSets.size > 0) {
1624+
if (newGroupedFieldSets && newDeferMap) {
16611625
const newDeferredGroupedFieldSetRecords = executeDeferredGroupedFieldSets(
16621626
exeContext,
16631627
returnType,

0 commit comments

Comments
 (0)