Skip to content

Commit 44b356c

Browse files
committed
Add tests
1 parent d0a6082 commit 44b356c

22 files changed

+389
-150
lines changed

src/execution/collectFields.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AccumulatorMap } from '../jsutils/AccumulatorMap.js';
22
import { invariant } from '../jsutils/invariant.js';
3+
import type { Maybe } from '../jsutils/Maybe.js';
34
import type { ObjMap } from '../jsutils/ObjMap.js';
45

56
import type {
@@ -55,7 +56,7 @@ interface CollectFieldsContext {
5556
operation: OperationDefinitionNode;
5657
runtimeType: GraphQLObjectType;
5758
visitedFragmentNames: Set<string>;
58-
shouldProvideSuggestions: boolean;
59+
maskSuggestions: boolean;
5960
}
6061

6162
/**
@@ -74,7 +75,7 @@ export function collectFields(
7475
variableValues: VariableValues,
7576
runtimeType: GraphQLObjectType,
7677
operation: OperationDefinitionNode,
77-
shouldProvideSuggestions: boolean,
78+
maskSuggestions?: Maybe<boolean>,
7879
): {
7980
groupedFieldSet: GroupedFieldSet;
8081
newDeferUsages: ReadonlyArray<DeferUsage>;
@@ -88,7 +89,7 @@ export function collectFields(
8889
runtimeType,
8990
operation,
9091
visitedFragmentNames: new Set(),
91-
shouldProvideSuggestions,
92+
maskSuggestions: maskSuggestions ?? false,
9293
};
9394

9495
collectFieldsImpl(
@@ -118,7 +119,7 @@ export function collectSubfields(
118119
operation: OperationDefinitionNode,
119120
returnType: GraphQLObjectType,
120121
fieldDetailsList: FieldDetailsList,
121-
shouldProvideSuggestions: boolean,
122+
maskSuggestions?: Maybe<boolean>,
122123
): {
123124
groupedFieldSet: GroupedFieldSet;
124125
newDeferUsages: ReadonlyArray<DeferUsage>;
@@ -130,7 +131,7 @@ export function collectSubfields(
130131
runtimeType: returnType,
131132
operation,
132133
visitedFragmentNames: new Set(),
133-
shouldProvideSuggestions,
134+
maskSuggestions: maskSuggestions ?? false,
134135
};
135136
const subGroupedFieldSet = new AccumulatorMap<string, FieldDetails>();
136137
const newDeferUsages: Array<DeferUsage> = [];
@@ -178,12 +179,7 @@ function collectFieldsImpl(
178179
switch (selection.kind) {
179180
case Kind.FIELD: {
180181
if (
181-
!shouldIncludeNode(
182-
selection,
183-
variableValues,
184-
fragmentVariableValues,
185-
context.shouldProvideSuggestions,
186-
)
182+
!shouldIncludeNode(selection, variableValues, fragmentVariableValues)
187183
) {
188184
continue;
189185
}
@@ -200,7 +196,6 @@ function collectFieldsImpl(
200196
selection,
201197
variableValues,
202198
fragmentVariableValues,
203-
context.shouldProvideSuggestions,
204199
) ||
205200
!doesFragmentConditionMatch(schema, selection, runtimeType)
206201
) {
@@ -213,7 +208,6 @@ function collectFieldsImpl(
213208
fragmentVariableValues,
214209
selection,
215210
deferUsage,
216-
context.shouldProvideSuggestions,
217211
);
218212

219213
if (!newDeferUsage) {
@@ -248,7 +242,6 @@ function collectFieldsImpl(
248242
fragmentVariableValues,
249243
selection,
250244
deferUsage,
251-
context.shouldProvideSuggestions,
252245
);
253246

254247
if (
@@ -258,7 +251,6 @@ function collectFieldsImpl(
258251
selection,
259252
variableValues,
260253
fragmentVariableValues,
261-
context.shouldProvideSuggestions,
262254
))
263255
) {
264256
continue;
@@ -279,8 +271,8 @@ function collectFieldsImpl(
279271
selection,
280272
fragmentVariableSignatures,
281273
variableValues,
282-
context.shouldProvideSuggestions,
283274
fragmentVariableValues,
275+
false,
284276
);
285277
}
286278

@@ -316,19 +308,16 @@ function collectFieldsImpl(
316308
* deferred based on the experimental flag, defer directive present and
317309
* not disabled by the "if" argument.
318310
*/
319-
// eslint-disable-next-line @typescript-eslint/max-params
320311
function getDeferUsage(
321312
operation: OperationDefinitionNode,
322313
variableValues: VariableValues,
323314
fragmentVariableValues: VariableValues | undefined,
324315
node: FragmentSpreadNode | InlineFragmentNode,
325316
parentDeferUsage: DeferUsage | undefined,
326-
shouldProvideSuggestions: boolean,
327317
): DeferUsage | undefined {
328318
const defer = getDirectiveValues(
329319
GraphQLDeferDirective,
330320
node,
331-
shouldProvideSuggestions,
332321
variableValues,
333322
fragmentVariableValues,
334323
);
@@ -360,12 +349,10 @@ function shouldIncludeNode(
360349
node: FragmentSpreadNode | FieldNode | InlineFragmentNode,
361350
variableValues: VariableValues,
362351
fragmentVariableValues: VariableValues | undefined,
363-
shouldProvideSuggestions: boolean,
364352
): boolean {
365353
const skip = getDirectiveValues(
366354
GraphQLSkipDirective,
367355
node,
368-
shouldProvideSuggestions,
369356
variableValues,
370357
fragmentVariableValues,
371358
);
@@ -376,7 +363,6 @@ function shouldIncludeNode(
376363
const include = getDirectiveValues(
377364
GraphQLIncludeDirective,
378365
node,
379-
shouldProvideSuggestions,
380366
variableValues,
381367
fragmentVariableValues,
382368
);

src/execution/execute.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,16 @@ const collectSubfields = memoize3(
9898
returnType: GraphQLObjectType,
9999
fieldDetailsList: FieldDetailsList,
100100
) => {
101-
const {
102-
schema,
103-
fragments,
104-
operation,
105-
variableValues,
106-
shouldProvideSuggestions,
107-
} = validatedExecutionArgs;
101+
const { schema, fragments, operation, variableValues, maskSuggestions } =
102+
validatedExecutionArgs;
108103
return _collectSubfields(
109104
schema,
110105
fragments,
111106
variableValues,
112107
operation,
113108
returnType,
114109
fieldDetailsList,
115-
shouldProvideSuggestions,
110+
maskSuggestions,
116111
);
117112
},
118113
);
@@ -161,7 +156,7 @@ export interface ValidatedExecutionArgs {
161156
validatedExecutionArgs: ValidatedExecutionArgs,
162157
) => PromiseOrValue<ExecutionResult>;
163158
enableEarlyExecution: boolean;
164-
shouldProvideSuggestions: boolean;
159+
maskSuggestions: boolean;
165160
}
166161

167162
export interface ExecutionContext {
@@ -191,7 +186,7 @@ export interface ExecutionArgs {
191186
) => PromiseOrValue<ExecutionResult>
192187
>;
193188
enableEarlyExecution?: Maybe<boolean>;
194-
shouldProvideSuggestions?: Maybe<boolean>;
189+
maskSuggestions?: Maybe<boolean>;
195190
}
196191

197192
export interface StreamUsage {
@@ -322,7 +317,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
322317
rootValue,
323318
operation,
324319
variableValues,
325-
shouldProvideSuggestions,
320+
maskSuggestions,
326321
} = validatedExecutionArgs;
327322
const rootType = schema.getRootType(operation.operation);
328323
if (rootType == null) {
@@ -338,7 +333,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
338333
variableValues,
339334
rootType,
340335
operation,
341-
shouldProvideSuggestions,
336+
maskSuggestions,
342337
);
343338

344339
const { groupedFieldSet, newDeferUsages } = collectedFields;
@@ -516,7 +511,6 @@ export function validateExecutionArgs(
516511
subscribeFieldResolver,
517512
perEventExecutor,
518513
enableEarlyExecution,
519-
shouldProvideSuggestions,
520514
} = args;
521515

522516
// If the schema used for execution is invalid, throw an error.
@@ -570,14 +564,15 @@ export function validateExecutionArgs(
570564
// FIXME: https://github.com/graphql/graphql-js/issues/2203
571565
/* c8 ignore next */
572566
const variableDefinitions = operation.variableDefinitions ?? [];
567+
const maskSuggestions = args.maskSuggestions ?? false;
573568

574569
const variableValuesOrErrors = getVariableValues(
575570
schema,
576571
variableDefinitions,
577572
rawVariableValues ?? {},
578573
{
579574
maxErrors: 50,
580-
shouldProvideSuggestions: shouldProvideSuggestions ?? true,
575+
maskSuggestions,
581576
},
582577
);
583578

@@ -598,7 +593,7 @@ export function validateExecutionArgs(
598593
subscribeFieldResolver: subscribeFieldResolver ?? defaultFieldResolver,
599594
perEventExecutor: perEventExecutor ?? executeSubscriptionEvent,
600595
enableEarlyExecution: enableEarlyExecution === true,
601-
shouldProvideSuggestions: shouldProvideSuggestions ?? true,
596+
maskSuggestions,
602597
};
603598
}
604599

@@ -782,7 +777,8 @@ function executeField(
782777
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
783778
): PromiseOrValue<GraphQLWrappedResult<unknown>> | undefined {
784779
const validatedExecutionArgs = exeContext.validatedExecutionArgs;
785-
const { schema, contextValue, variableValues, shouldProvideSuggestions } = validatedExecutionArgs;
780+
const { schema, contextValue, variableValues, maskSuggestions } =
781+
validatedExecutionArgs;
786782
const fieldName = fieldDetailsList[0].node.name.value;
787783
const fieldDef = schema.getField(parentType, fieldName);
788784
if (!fieldDef) {
@@ -809,8 +805,8 @@ function executeField(
809805
fieldDetailsList[0].node,
810806
fieldDef.args,
811807
variableValues,
812-
shouldProvideSuggestions,
813808
fieldDetailsList[0].fragmentVariableValues,
809+
maskSuggestions,
814810
);
815811

816812
// The resolve function's optional third argument is a context value that
@@ -1114,16 +1110,15 @@ function getStreamUsage(
11141110
._streamUsage;
11151111
}
11161112

1117-
const { operation, variableValues, shouldProvideSuggestions } =
1118-
validatedExecutionArgs;
1113+
const { operation, variableValues, maskSuggestions } = validatedExecutionArgs;
11191114
// validation only allows equivalent streams on multiple fields, so it is
11201115
// safe to only check the first fieldNode for the stream directive
11211116
const stream = getDirectiveValues(
11221117
GraphQLStreamDirective,
11231118
fieldDetailsList[0].node,
1124-
shouldProvideSuggestions,
11251119
variableValues,
11261120
fieldDetailsList[0].fragmentVariableValues,
1121+
maskSuggestions,
11271122
);
11281123

11291124
if (!stream) {
@@ -2088,7 +2083,7 @@ function executeSubscription(
20882083
contextValue,
20892084
operation,
20902085
variableValues,
2091-
shouldProvideSuggestions,
2086+
maskSuggestions,
20922087
} = validatedExecutionArgs;
20932088

20942089
const rootType = schema.getSubscriptionType();
@@ -2105,7 +2100,7 @@ function executeSubscription(
21052100
variableValues,
21062101
rootType,
21072102
operation,
2108-
shouldProvideSuggestions,
2103+
maskSuggestions,
21092104
);
21102105

21112106
const firstRootField = groupedFieldSet.entries().next().value as [
@@ -2142,8 +2137,8 @@ function executeSubscription(
21422137
const args = getArgumentValues(
21432138
fieldDef,
21442139
fieldNodes[0],
2145-
validatedExecutionArgs.shouldProvideSuggestions,
21462140
variableValues,
2141+
maskSuggestions,
21472142
);
21482143

21492144
// Call the `subscribe()` resolver or the default resolver to produce an

0 commit comments

Comments
 (0)