Skip to content

Commit

Permalink
Use context instead
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Feb 26, 2025
1 parent 6b658cf commit 2ffbde6
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ interface CollectFieldsContext {
visitedFragmentNames: Set<string>;
hideSuggestions: boolean;
forbiddenDirectiveInstances: Array<DirectiveNode>;
forbidSkipAndInclude: boolean;
}

/**
Expand All @@ -78,7 +79,7 @@ export function collectFields(
runtimeType: GraphQLObjectType,
selectionSet: SelectionSetNode,
hideSuggestions: boolean,
forbidSkipInclude = false,
forbidSkipAndInclude = false,
): {
groupedFieldSet: GroupedFieldSet;
newDeferUsages: ReadonlyArray<DeferUsage>;
Expand All @@ -94,17 +95,10 @@ export function collectFields(
visitedFragmentNames: new Set(),
hideSuggestions,
forbiddenDirectiveInstances: [],
forbidSkipAndInclude,
};

collectFieldsImpl(
context,
selectionSet,
groupedFieldSet,
newDeferUsages,
undefined,
undefined,
forbidSkipInclude,
);
collectFieldsImpl(context, selectionSet, groupedFieldSet, newDeferUsages);
return {
groupedFieldSet,
newDeferUsages,
Expand Down Expand Up @@ -177,7 +171,6 @@ function collectFieldsImpl(
newDeferUsages: Array<DeferUsage>,
deferUsage?: DeferUsage,
fragmentVariableValues?: VariableValues,
forbidSkipInclude = false,
): void {
const {
schema,
Expand All @@ -198,7 +191,6 @@ function collectFieldsImpl(
variableValues,
fragmentVariableValues,
hideSuggestions,
forbidSkipInclude,
)
) {
continue;
Expand All @@ -218,7 +210,6 @@ function collectFieldsImpl(
variableValues,
fragmentVariableValues,
hideSuggestions,
forbidSkipInclude,
) ||
!doesFragmentConditionMatch(schema, selection, runtimeType)
) {
Expand Down Expand Up @@ -266,7 +257,6 @@ function collectFieldsImpl(
variableValues,
fragmentVariableValues,
hideSuggestions,
forbidSkipInclude,
)
) {
continue;
Expand Down Expand Up @@ -368,12 +358,11 @@ function shouldIncludeNode(
variableValues: VariableValues,
fragmentVariableValues: VariableValues | undefined,
hideSuggestions: Maybe<boolean>,
forbidSkipInclude: boolean,
): boolean {
const skipDirectiveNode = node.directives?.find(
(directive) => directive.name.value === GraphQLSkipDirective.name,
);
if (skipDirectiveNode && forbidSkipInclude) {
if (skipDirectiveNode && context.forbidSkipAndInclude) {
context.forbiddenDirectiveInstances.push(skipDirectiveNode);
return false;
}
Expand All @@ -393,7 +382,7 @@ function shouldIncludeNode(
const includeDirectiveNode = node.directives?.find(
(directive) => directive.name.value === GraphQLIncludeDirective.name,
);
if (includeDirectiveNode && forbidSkipInclude) {
if (includeDirectiveNode && context.forbidSkipAndInclude) {
context.forbiddenDirectiveInstances.push(includeDirectiveNode);
return false;
}
Expand Down

0 comments on commit 2ffbde6

Please sign in to comment.