Skip to content

Commit ac076da

Browse files
committed
Add tests
1 parent d0a6082 commit ac076da

23 files changed

+377
-131
lines changed

src/execution/collectFields.ts

+7-17
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface CollectFieldsContext {
5555
operation: OperationDefinitionNode;
5656
runtimeType: GraphQLObjectType;
5757
visitedFragmentNames: Set<string>;
58-
shouldProvideSuggestions: boolean;
58+
maskSuggestions: boolean
5959
}
6060

6161
/**
@@ -74,7 +74,7 @@ export function collectFields(
7474
variableValues: VariableValues,
7575
runtimeType: GraphQLObjectType,
7676
operation: OperationDefinitionNode,
77-
shouldProvideSuggestions: boolean,
77+
maskSuggestions: boolean,
7878
): {
7979
groupedFieldSet: GroupedFieldSet;
8080
newDeferUsages: ReadonlyArray<DeferUsage>;
@@ -88,7 +88,7 @@ export function collectFields(
8888
runtimeType,
8989
operation,
9090
visitedFragmentNames: new Set(),
91-
shouldProvideSuggestions,
91+
maskSuggestions,
9292
};
9393

9494
collectFieldsImpl(
@@ -118,8 +118,8 @@ export function collectSubfields(
118118
operation: OperationDefinitionNode,
119119
returnType: GraphQLObjectType,
120120
fieldDetailsList: FieldDetailsList,
121-
shouldProvideSuggestions: boolean,
122-
): {
121+
maskSuggestions: boolean,
122+
): {
123123
groupedFieldSet: GroupedFieldSet;
124124
newDeferUsages: ReadonlyArray<DeferUsage>;
125125
} {
@@ -130,7 +130,7 @@ export function collectSubfields(
130130
runtimeType: returnType,
131131
operation,
132132
visitedFragmentNames: new Set(),
133-
shouldProvideSuggestions,
133+
maskSuggestions
134134
};
135135
const subGroupedFieldSet = new AccumulatorMap<string, FieldDetails>();
136136
const newDeferUsages: Array<DeferUsage> = [];
@@ -182,7 +182,6 @@ function collectFieldsImpl(
182182
selection,
183183
variableValues,
184184
fragmentVariableValues,
185-
context.shouldProvideSuggestions,
186185
)
187186
) {
188187
continue;
@@ -200,7 +199,6 @@ function collectFieldsImpl(
200199
selection,
201200
variableValues,
202201
fragmentVariableValues,
203-
context.shouldProvideSuggestions,
204202
) ||
205203
!doesFragmentConditionMatch(schema, selection, runtimeType)
206204
) {
@@ -213,7 +211,6 @@ function collectFieldsImpl(
213211
fragmentVariableValues,
214212
selection,
215213
deferUsage,
216-
context.shouldProvideSuggestions,
217214
);
218215

219216
if (!newDeferUsage) {
@@ -248,7 +245,6 @@ function collectFieldsImpl(
248245
fragmentVariableValues,
249246
selection,
250247
deferUsage,
251-
context.shouldProvideSuggestions,
252248
);
253249

254250
if (
@@ -258,7 +254,6 @@ function collectFieldsImpl(
258254
selection,
259255
variableValues,
260256
fragmentVariableValues,
261-
context.shouldProvideSuggestions,
262257
))
263258
) {
264259
continue;
@@ -279,7 +274,7 @@ function collectFieldsImpl(
279274
selection,
280275
fragmentVariableSignatures,
281276
variableValues,
282-
context.shouldProvideSuggestions,
277+
false,
283278
fragmentVariableValues,
284279
);
285280
}
@@ -323,12 +318,10 @@ function getDeferUsage(
323318
fragmentVariableValues: VariableValues | undefined,
324319
node: FragmentSpreadNode | InlineFragmentNode,
325320
parentDeferUsage: DeferUsage | undefined,
326-
shouldProvideSuggestions: boolean,
327321
): DeferUsage | undefined {
328322
const defer = getDirectiveValues(
329323
GraphQLDeferDirective,
330324
node,
331-
shouldProvideSuggestions,
332325
variableValues,
333326
fragmentVariableValues,
334327
);
@@ -360,12 +353,10 @@ function shouldIncludeNode(
360353
node: FragmentSpreadNode | FieldNode | InlineFragmentNode,
361354
variableValues: VariableValues,
362355
fragmentVariableValues: VariableValues | undefined,
363-
shouldProvideSuggestions: boolean,
364356
): boolean {
365357
const skip = getDirectiveValues(
366358
GraphQLSkipDirective,
367359
node,
368-
shouldProvideSuggestions,
369360
variableValues,
370361
fragmentVariableValues,
371362
);
@@ -376,7 +367,6 @@ function shouldIncludeNode(
376367
const include = getDirectiveValues(
377368
GraphQLIncludeDirective,
378369
node,
379-
shouldProvideSuggestions,
380370
variableValues,
381371
fragmentVariableValues,
382372
);

src/execution/execute.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const collectSubfields = memoize3(
103103
fragments,
104104
operation,
105105
variableValues,
106-
shouldProvideSuggestions,
106+
maskSuggestions,
107107
} = validatedExecutionArgs;
108108
return _collectSubfields(
109109
schema,
@@ -112,7 +112,7 @@ const collectSubfields = memoize3(
112112
operation,
113113
returnType,
114114
fieldDetailsList,
115-
shouldProvideSuggestions,
115+
maskSuggestions,
116116
);
117117
},
118118
);
@@ -161,7 +161,7 @@ export interface ValidatedExecutionArgs {
161161
validatedExecutionArgs: ValidatedExecutionArgs,
162162
) => PromiseOrValue<ExecutionResult>;
163163
enableEarlyExecution: boolean;
164-
shouldProvideSuggestions: boolean;
164+
maskSuggestions: boolean;
165165
}
166166

167167
export interface ExecutionContext {
@@ -191,7 +191,7 @@ export interface ExecutionArgs {
191191
) => PromiseOrValue<ExecutionResult>
192192
>;
193193
enableEarlyExecution?: Maybe<boolean>;
194-
shouldProvideSuggestions?: Maybe<boolean>;
194+
maskSuggestions?: Maybe<boolean>;
195195
}
196196

197197
export interface StreamUsage {
@@ -322,7 +322,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
322322
rootValue,
323323
operation,
324324
variableValues,
325-
shouldProvideSuggestions,
325+
maskSuggestions,
326326
} = validatedExecutionArgs;
327327
const rootType = schema.getRootType(operation.operation);
328328
if (rootType == null) {
@@ -338,7 +338,7 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
338338
variableValues,
339339
rootType,
340340
operation,
341-
shouldProvideSuggestions,
341+
maskSuggestions,
342342
);
343343

344344
const { groupedFieldSet, newDeferUsages } = collectedFields;
@@ -516,7 +516,6 @@ export function validateExecutionArgs(
516516
subscribeFieldResolver,
517517
perEventExecutor,
518518
enableEarlyExecution,
519-
shouldProvideSuggestions,
520519
} = args;
521520

522521
// If the schema used for execution is invalid, throw an error.
@@ -570,14 +569,15 @@ export function validateExecutionArgs(
570569
// FIXME: https://github.com/graphql/graphql-js/issues/2203
571570
/* c8 ignore next */
572571
const variableDefinitions = operation.variableDefinitions ?? [];
572+
const maskSuggestions = args.maskSuggestions ?? false;
573573

574574
const variableValuesOrErrors = getVariableValues(
575575
schema,
576576
variableDefinitions,
577577
rawVariableValues ?? {},
578578
{
579579
maxErrors: 50,
580-
shouldProvideSuggestions: shouldProvideSuggestions ?? true,
580+
maskSuggestions
581581
},
582582
);
583583

@@ -598,7 +598,7 @@ export function validateExecutionArgs(
598598
subscribeFieldResolver: subscribeFieldResolver ?? defaultFieldResolver,
599599
perEventExecutor: perEventExecutor ?? executeSubscriptionEvent,
600600
enableEarlyExecution: enableEarlyExecution === true,
601-
shouldProvideSuggestions: shouldProvideSuggestions ?? true,
601+
maskSuggestions,
602602
};
603603
}
604604

@@ -782,7 +782,7 @@ function executeField(
782782
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
783783
): PromiseOrValue<GraphQLWrappedResult<unknown>> | undefined {
784784
const validatedExecutionArgs = exeContext.validatedExecutionArgs;
785-
const { schema, contextValue, variableValues, shouldProvideSuggestions } = validatedExecutionArgs;
785+
const { schema, contextValue, variableValues, maskSuggestions } = validatedExecutionArgs;
786786
const fieldName = fieldDetailsList[0].node.name.value;
787787
const fieldDef = schema.getField(parentType, fieldName);
788788
if (!fieldDef) {
@@ -809,8 +809,8 @@ function executeField(
809809
fieldDetailsList[0].node,
810810
fieldDef.args,
811811
variableValues,
812-
shouldProvideSuggestions,
813812
fieldDetailsList[0].fragmentVariableValues,
813+
maskSuggestions,
814814
);
815815

816816
// The resolve function's optional third argument is a context value that
@@ -1114,16 +1114,16 @@ function getStreamUsage(
11141114
._streamUsage;
11151115
}
11161116

1117-
const { operation, variableValues, shouldProvideSuggestions } =
1117+
const { operation, variableValues, maskSuggestions } =
11181118
validatedExecutionArgs;
11191119
// validation only allows equivalent streams on multiple fields, so it is
11201120
// safe to only check the first fieldNode for the stream directive
11211121
const stream = getDirectiveValues(
11221122
GraphQLStreamDirective,
11231123
fieldDetailsList[0].node,
1124-
shouldProvideSuggestions,
11251124
variableValues,
11261125
fieldDetailsList[0].fragmentVariableValues,
1126+
maskSuggestions,
11271127
);
11281128

11291129
if (!stream) {
@@ -2088,7 +2088,7 @@ function executeSubscription(
20882088
contextValue,
20892089
operation,
20902090
variableValues,
2091-
shouldProvideSuggestions,
2091+
maskSuggestions,
20922092
} = validatedExecutionArgs;
20932093

20942094
const rootType = schema.getSubscriptionType();
@@ -2105,7 +2105,7 @@ function executeSubscription(
21052105
variableValues,
21062106
rootType,
21072107
operation,
2108-
shouldProvideSuggestions,
2108+
maskSuggestions,
21092109
);
21102110

21112111
const firstRootField = groupedFieldSet.entries().next().value as [
@@ -2142,8 +2142,8 @@ function executeSubscription(
21422142
const args = getArgumentValues(
21432143
fieldDef,
21442144
fieldNodes[0],
2145-
validatedExecutionArgs.shouldProvideSuggestions,
21462145
variableValues,
2146+
validatedExecutionArgs.maskSuggestions,
21472147
);
21482148

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

0 commit comments

Comments
 (0)