Skip to content

Commit 2ffbde6

Browse files
committed
Use context instead
1 parent 6b658cf commit 2ffbde6

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/execution/collectFields.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ interface CollectFieldsContext {
5959
visitedFragmentNames: Set<string>;
6060
hideSuggestions: boolean;
6161
forbiddenDirectiveInstances: Array<DirectiveNode>;
62+
forbidSkipAndInclude: boolean;
6263
}
6364

6465
/**
@@ -78,7 +79,7 @@ export function collectFields(
7879
runtimeType: GraphQLObjectType,
7980
selectionSet: SelectionSetNode,
8081
hideSuggestions: boolean,
81-
forbidSkipInclude = false,
82+
forbidSkipAndInclude = false,
8283
): {
8384
groupedFieldSet: GroupedFieldSet;
8485
newDeferUsages: ReadonlyArray<DeferUsage>;
@@ -94,17 +95,10 @@ export function collectFields(
9495
visitedFragmentNames: new Set(),
9596
hideSuggestions,
9697
forbiddenDirectiveInstances: [],
98+
forbidSkipAndInclude,
9799
};
98100

99-
collectFieldsImpl(
100-
context,
101-
selectionSet,
102-
groupedFieldSet,
103-
newDeferUsages,
104-
undefined,
105-
undefined,
106-
forbidSkipInclude,
107-
);
101+
collectFieldsImpl(context, selectionSet, groupedFieldSet, newDeferUsages);
108102
return {
109103
groupedFieldSet,
110104
newDeferUsages,
@@ -177,7 +171,6 @@ function collectFieldsImpl(
177171
newDeferUsages: Array<DeferUsage>,
178172
deferUsage?: DeferUsage,
179173
fragmentVariableValues?: VariableValues,
180-
forbidSkipInclude = false,
181174
): void {
182175
const {
183176
schema,
@@ -198,7 +191,6 @@ function collectFieldsImpl(
198191
variableValues,
199192
fragmentVariableValues,
200193
hideSuggestions,
201-
forbidSkipInclude,
202194
)
203195
) {
204196
continue;
@@ -218,7 +210,6 @@ function collectFieldsImpl(
218210
variableValues,
219211
fragmentVariableValues,
220212
hideSuggestions,
221-
forbidSkipInclude,
222213
) ||
223214
!doesFragmentConditionMatch(schema, selection, runtimeType)
224215
) {
@@ -266,7 +257,6 @@ function collectFieldsImpl(
266257
variableValues,
267258
fragmentVariableValues,
268259
hideSuggestions,
269-
forbidSkipInclude,
270260
)
271261
) {
272262
continue;
@@ -368,12 +358,11 @@ function shouldIncludeNode(
368358
variableValues: VariableValues,
369359
fragmentVariableValues: VariableValues | undefined,
370360
hideSuggestions: Maybe<boolean>,
371-
forbidSkipInclude: boolean,
372361
): boolean {
373362
const skipDirectiveNode = node.directives?.find(
374363
(directive) => directive.name.value === GraphQLSkipDirective.name,
375364
);
376-
if (skipDirectiveNode && forbidSkipInclude) {
365+
if (skipDirectiveNode && context.forbidSkipAndInclude) {
377366
context.forbiddenDirectiveInstances.push(skipDirectiveNode);
378367
return false;
379368
}
@@ -393,7 +382,7 @@ function shouldIncludeNode(
393382
const includeDirectiveNode = node.directives?.find(
394383
(directive) => directive.name.value === GraphQLIncludeDirective.name,
395384
);
396-
if (includeDirectiveNode && forbidSkipInclude) {
385+
if (includeDirectiveNode && context.forbidSkipAndInclude) {
397386
context.forbiddenDirectiveInstances.push(includeDirectiveNode);
398387
return false;
399388
}

0 commit comments

Comments
 (0)