Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move subscription @defer check out of collectFields #4308

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading