Skip to content

Commit

Permalink
move subscription @defer check out of collectFields (#4308)
Browse files Browse the repository at this point in the history
this way, if (when?) we re-enable incemental delivery support with subscriptions, the signature of collect fields will not need to change
  • Loading branch information
yaacovCR authored Dec 10, 2024
1 parent 50d555c commit 32c5b0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
15 changes: 0 additions & 15 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AccumulatorMap } from '../jsutils/AccumulatorMap.js';
import { invariant } from '../jsutils/invariant.js';
import type { ObjMap } from '../jsutils/ObjMap.js';

import type {
Expand All @@ -10,7 +9,6 @@ import type {
OperationDefinitionNode,
SelectionSetNode,
} from '../language/ast.js';
import { OperationTypeNode } from '../language/ast.js';
import { Kind } from '../language/kinds.js';

import type { GraphQLObjectType } from '../type/definition.js';
Expand Down Expand Up @@ -52,7 +50,6 @@ interface CollectFieldsContext {
schema: GraphQLSchema;
fragments: ObjMap<FragmentDetails>;
variableValues: VariableValues;
operation: OperationDefinitionNode;
runtimeType: GraphQLObjectType;
visitedFragmentNames: Set<string>;
hideSuggestions: boolean;
Expand Down Expand Up @@ -86,7 +83,6 @@ export function collectFields(
fragments,
variableValues,
runtimeType,
operation,
visitedFragmentNames: new Set(),
hideSuggestions,
};
Expand Down Expand Up @@ -115,7 +111,6 @@ export function collectSubfields(
schema: GraphQLSchema,
fragments: ObjMap<FragmentDetails>,
variableValues: VariableValues,
operation: OperationDefinitionNode,
returnType: GraphQLObjectType,
fieldDetailsList: FieldDetailsList,
hideSuggestions: boolean,
Expand All @@ -128,7 +123,6 @@ export function collectSubfields(
fragments,
variableValues,
runtimeType: returnType,
operation,
visitedFragmentNames: new Set(),
hideSuggestions,
};
Expand Down Expand Up @@ -170,7 +164,6 @@ function collectFieldsImpl(
fragments,
variableValues,
runtimeType,
operation,
visitedFragmentNames,
hideSuggestions,
} = context;
Expand Down Expand Up @@ -203,7 +196,6 @@ function collectFieldsImpl(
}

const newDeferUsage = getDeferUsage(
operation,
variableValues,
fragmentVariableValues,
selection,
Expand Down Expand Up @@ -237,7 +229,6 @@ function collectFieldsImpl(
const fragName = selection.name.value;

const newDeferUsage = getDeferUsage(
operation,
variableValues,
fragmentVariableValues,
selection,
Expand Down Expand Up @@ -309,7 +300,6 @@ function collectFieldsImpl(
* not disabled by the "if" argument.
*/
function getDeferUsage(
operation: OperationDefinitionNode,
variableValues: VariableValues,
fragmentVariableValues: VariableValues | undefined,
node: FragmentSpreadNode | InlineFragmentNode,
Expand All @@ -330,11 +320,6 @@ function getDeferUsage(
return;
}

invariant(
operation.operation !== OperationTypeNode.SUBSCRIPTION,
'`@defer` directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.',
);

return {
label: typeof defer.label === 'string' ? defer.label : undefined,
parentDeferUsage,
Expand Down
16 changes: 13 additions & 3 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ const collectSubfields = memoize3(
returnType: GraphQLObjectType,
fieldDetailsList: FieldDetailsList,
) => {
const { schema, fragments, operation, variableValues, hideSuggestions } =
const { schema, fragments, variableValues, hideSuggestions } =
validatedExecutionArgs;
return _collectSubfields(
schema,
fragments,
variableValues,
operation,
returnType,
fieldDetailsList,
hideSuggestions,
Expand Down Expand Up @@ -1894,13 +1893,24 @@ function collectAndExecuteSubfields(
incrementalContext: IncrementalContext | undefined,
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
): PromiseOrValue<GraphQLWrappedResult<ObjMap<unknown>>> {
const validatedExecutionArgs = exeContext.validatedExecutionArgs;

// Collect sub-fields to execute to complete this value.
const collectedSubfields = collectSubfields(
exeContext.validatedExecutionArgs,
validatedExecutionArgs,
returnType,
fieldDetailsList,
);
const { groupedFieldSet, newDeferUsages } = collectedSubfields;

if (newDeferUsages.length > 0) {
invariant(
validatedExecutionArgs.operation.operation !==
OperationTypeNode.SUBSCRIPTION,
'`@defer` directive not supported on subscription operations. Disable `@defer` by setting the `if` argument to `false`.',
);
}

return executeSubExecutionPlan(
exeContext,
returnType,
Expand Down

0 comments on commit 32c5b0d

Please sign in to comment.