Skip to content

Commit 32c5b0d

Browse files
authored
move subscription @defer check out of collectFields (#4308)
this way, if (when?) we re-enable incemental delivery support with subscriptions, the signature of collect fields will not need to change
1 parent 50d555c commit 32c5b0d

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/execution/collectFields.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AccumulatorMap } from '../jsutils/AccumulatorMap.js';
2-
import { invariant } from '../jsutils/invariant.js';
32
import type { ObjMap } from '../jsutils/ObjMap.js';
43

54
import type {
@@ -10,7 +9,6 @@ import type {
109
OperationDefinitionNode,
1110
SelectionSetNode,
1211
} from '../language/ast.js';
13-
import { OperationTypeNode } from '../language/ast.js';
1412
import { Kind } from '../language/kinds.js';
1513

1614
import type { GraphQLObjectType } from '../type/definition.js';
@@ -52,7 +50,6 @@ interface CollectFieldsContext {
5250
schema: GraphQLSchema;
5351
fragments: ObjMap<FragmentDetails>;
5452
variableValues: VariableValues;
55-
operation: OperationDefinitionNode;
5653
runtimeType: GraphQLObjectType;
5754
visitedFragmentNames: Set<string>;
5855
hideSuggestions: boolean;
@@ -86,7 +83,6 @@ export function collectFields(
8683
fragments,
8784
variableValues,
8885
runtimeType,
89-
operation,
9086
visitedFragmentNames: new Set(),
9187
hideSuggestions,
9288
};
@@ -115,7 +111,6 @@ export function collectSubfields(
115111
schema: GraphQLSchema,
116112
fragments: ObjMap<FragmentDetails>,
117113
variableValues: VariableValues,
118-
operation: OperationDefinitionNode,
119114
returnType: GraphQLObjectType,
120115
fieldDetailsList: FieldDetailsList,
121116
hideSuggestions: boolean,
@@ -128,7 +123,6 @@ export function collectSubfields(
128123
fragments,
129124
variableValues,
130125
runtimeType: returnType,
131-
operation,
132126
visitedFragmentNames: new Set(),
133127
hideSuggestions,
134128
};
@@ -170,7 +164,6 @@ function collectFieldsImpl(
170164
fragments,
171165
variableValues,
172166
runtimeType,
173-
operation,
174167
visitedFragmentNames,
175168
hideSuggestions,
176169
} = context;
@@ -203,7 +196,6 @@ function collectFieldsImpl(
203196
}
204197

205198
const newDeferUsage = getDeferUsage(
206-
operation,
207199
variableValues,
208200
fragmentVariableValues,
209201
selection,
@@ -237,7 +229,6 @@ function collectFieldsImpl(
237229
const fragName = selection.name.value;
238230

239231
const newDeferUsage = getDeferUsage(
240-
operation,
241232
variableValues,
242233
fragmentVariableValues,
243234
selection,
@@ -309,7 +300,6 @@ function collectFieldsImpl(
309300
* not disabled by the "if" argument.
310301
*/
311302
function getDeferUsage(
312-
operation: OperationDefinitionNode,
313303
variableValues: VariableValues,
314304
fragmentVariableValues: VariableValues | undefined,
315305
node: FragmentSpreadNode | InlineFragmentNode,
@@ -330,11 +320,6 @@ function getDeferUsage(
330320
return;
331321
}
332322

333-
invariant(
334-
operation.operation !== OperationTypeNode.SUBSCRIPTION,
335-
'`@defer` directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.',
336-
);
337-
338323
return {
339324
label: typeof defer.label === 'string' ? defer.label : undefined,
340325
parentDeferUsage,

src/execution/execute.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,12 @@ const collectSubfields = memoize3(
103103
returnType: GraphQLObjectType,
104104
fieldDetailsList: FieldDetailsList,
105105
) => {
106-
const { schema, fragments, operation, variableValues, hideSuggestions } =
106+
const { schema, fragments, variableValues, hideSuggestions } =
107107
validatedExecutionArgs;
108108
return _collectSubfields(
109109
schema,
110110
fragments,
111111
variableValues,
112-
operation,
113112
returnType,
114113
fieldDetailsList,
115114
hideSuggestions,
@@ -1894,13 +1893,24 @@ function collectAndExecuteSubfields(
18941893
incrementalContext: IncrementalContext | undefined,
18951894
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
18961895
): PromiseOrValue<GraphQLWrappedResult<ObjMap<unknown>>> {
1896+
const validatedExecutionArgs = exeContext.validatedExecutionArgs;
1897+
18971898
// Collect sub-fields to execute to complete this value.
18981899
const collectedSubfields = collectSubfields(
1899-
exeContext.validatedExecutionArgs,
1900+
validatedExecutionArgs,
19001901
returnType,
19011902
fieldDetailsList,
19021903
);
19031904
const { groupedFieldSet, newDeferUsages } = collectedSubfields;
1905+
1906+
if (newDeferUsages.length > 0) {
1907+
invariant(
1908+
validatedExecutionArgs.operation.operation !==
1909+
OperationTypeNode.SUBSCRIPTION,
1910+
'`@defer` directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.',
1911+
);
1912+
}
1913+
19041914
return executeSubExecutionPlan(
19051915
exeContext,
19061916
returnType,

0 commit comments

Comments
 (0)