Skip to content

Commit 9e39e59

Browse files
authored
polish: skip recollecting a named fragment's selections even when deferred (#4320)
In the "old" duplicating version of incremental delivery, `collectFields()` was responsible for branching, and it therefore allowed processing a deferred named fragment even if that named fragment had already been visited as a regular non-deferred named fragment. One could have argued against that, as the old version had the concept of inlining, and so we could have just skipped the named fragment and considered it inlined, but chose not to do that. Now that we have an algorithm without duplication of fields, revisiting a named fragment will have no effect, as within the `buildExecutionPlan()` step, all the duplicated fields will be removed. So we can just remove the exception and go back to the version pre-incremental delivery where we always skip a visited named fragment. Note that we still only consider a named fragment to have been visited if it was not marked as deferred, because in the case of overlapping deferred and non-deferred spreads of the same named fragment, we need to visit it as the non-deferred spread to actually realize that it is non-deferred. [As an aside, looks like I made a mistake in #3994 => we would never have wanted to ignore the result of `shouldIncludeNode()` => since we are removing all ignoring of these conditions with respect to defer, this PR "fixes" that mistake as well.]
1 parent 76c0e90 commit 9e39e59

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/execution/collectFields.ts

+9-14
Original file line numberDiff line numberDiff line change
@@ -222,21 +222,9 @@ function collectFieldsImpl(
222222
case Kind.FRAGMENT_SPREAD: {
223223
const fragName = selection.name.value;
224224

225-
const newDeferUsage = getDeferUsage(
226-
variableValues,
227-
fragmentVariableValues,
228-
selection,
229-
deferUsage,
230-
);
231-
232225
if (
233-
!newDeferUsage &&
234-
(visitedFragmentNames.has(fragName) ||
235-
!shouldIncludeNode(
236-
selection,
237-
variableValues,
238-
fragmentVariableValues,
239-
))
226+
visitedFragmentNames.has(fragName) ||
227+
!shouldIncludeNode(selection, variableValues, fragmentVariableValues)
240228
) {
241229
continue;
242230
}
@@ -249,6 +237,13 @@ function collectFieldsImpl(
249237
continue;
250238
}
251239

240+
const newDeferUsage = getDeferUsage(
241+
variableValues,
242+
fragmentVariableValues,
243+
selection,
244+
deferUsage,
245+
);
246+
252247
const fragmentVariableSignatures = fragment.variableSignatures;
253248
let newFragmentVariableValues: VariableValues | undefined;
254249
if (fragmentVariableSignatures) {

0 commit comments

Comments
 (0)