Skip to content

Commit 3d46cac

Browse files
committed
Add tests
1 parent d0a6082 commit 3d46cac

22 files changed

+374
-148
lines changed

src/execution/collectFields.ts

Lines changed: 7 additions & 22 deletions
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,7 +118,7 @@ export function collectSubfields(
118118
operation: OperationDefinitionNode,
119119
returnType: GraphQLObjectType,
120120
fieldDetailsList: FieldDetailsList,
121-
shouldProvideSuggestions: boolean,
121+
maskSuggestions: boolean,
122122
): {
123123
groupedFieldSet: GroupedFieldSet;
124124
newDeferUsages: ReadonlyArray<DeferUsage>;
@@ -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> = [];
@@ -178,12 +178,7 @@ function collectFieldsImpl(
178178
switch (selection.kind) {
179179
case Kind.FIELD: {
180180
if (
181-
!shouldIncludeNode(
182-
selection,
183-
variableValues,
184-
fragmentVariableValues,
185-
context.shouldProvideSuggestions,
186-
)
181+
!shouldIncludeNode(selection, variableValues, fragmentVariableValues)
187182
) {
188183
continue;
189184
}
@@ -200,7 +195,6 @@ function collectFieldsImpl(
200195
selection,
201196
variableValues,
202197
fragmentVariableValues,
203-
context.shouldProvideSuggestions,
204198
) ||
205199
!doesFragmentConditionMatch(schema, selection, runtimeType)
206200
) {
@@ -213,7 +207,6 @@ function collectFieldsImpl(
213207
fragmentVariableValues,
214208
selection,
215209
deferUsage,
216-
context.shouldProvideSuggestions,
217210
);
218211

219212
if (!newDeferUsage) {
@@ -248,7 +241,6 @@ function collectFieldsImpl(
248241
fragmentVariableValues,
249242
selection,
250243
deferUsage,
251-
context.shouldProvideSuggestions,
252244
);
253245

254246
if (
@@ -258,7 +250,6 @@ function collectFieldsImpl(
258250
selection,
259251
variableValues,
260252
fragmentVariableValues,
261-
context.shouldProvideSuggestions,
262253
))
263254
) {
264255
continue;
@@ -279,7 +270,7 @@ function collectFieldsImpl(
279270
selection,
280271
fragmentVariableSignatures,
281272
variableValues,
282-
context.shouldProvideSuggestions,
273+
false,
283274
fragmentVariableValues,
284275
);
285276
}
@@ -316,19 +307,16 @@ function collectFieldsImpl(
316307
* deferred based on the experimental flag, defer directive present and
317308
* not disabled by the "if" argument.
318309
*/
319-
// eslint-disable-next-line @typescript-eslint/max-params
320310
function getDeferUsage(
321311
operation: OperationDefinitionNode,
322312
variableValues: VariableValues,
323313
fragmentVariableValues: VariableValues | undefined,
324314
node: FragmentSpreadNode | InlineFragmentNode,
325315
parentDeferUsage: DeferUsage | undefined,
326-
shouldProvideSuggestions: boolean,
327316
): DeferUsage | undefined {
328317
const defer = getDirectiveValues(
329318
GraphQLDeferDirective,
330319
node,
331-
shouldProvideSuggestions,
332320
variableValues,
333321
fragmentVariableValues,
334322
);
@@ -360,12 +348,10 @@ function shouldIncludeNode(
360348
node: FragmentSpreadNode | FieldNode | InlineFragmentNode,
361349
variableValues: VariableValues,
362350
fragmentVariableValues: VariableValues | undefined,
363-
shouldProvideSuggestions: boolean,
364351
): boolean {
365352
const skip = getDirectiveValues(
366353
GraphQLSkipDirective,
367354
node,
368-
shouldProvideSuggestions,
369355
variableValues,
370356
fragmentVariableValues,
371357
);
@@ -376,7 +362,6 @@ function shouldIncludeNode(
376362
const include = getDirectiveValues(
377363
GraphQLIncludeDirective,
378364
node,
379-
shouldProvideSuggestions,
380365
variableValues,
381366
fragmentVariableValues,
382367
);

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+
validatedExecutionArgs.maskSuggestions,
21472142
);
21482143

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

0 commit comments

Comments
 (0)