Skip to content

Commit bc0de11

Browse files
committed
Add tests
1 parent 6bbfb01 commit bc0de11

22 files changed

+388
-150
lines changed

src/execution/collectFields.ts

Lines changed: 8 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> = [];
@@ -172,18 +172,14 @@ function collectFieldsImpl(
172172
runtimeType,
173173
operation,
174174
visitedFragmentNames,
175+
maskSuggestions,
175176
} = context;
176177

177178
for (const selection of selectionSet.selections) {
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+
maskSuggestions,
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: 17 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,14 +1110,12 @@ function getStreamUsage(
11141110
._streamUsage;
11151111
}
11161112

1117-
const { operation, variableValues, shouldProvideSuggestions } =
1118-
validatedExecutionArgs;
1113+
const { operation, variableValues } = 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,
11271121
);
@@ -2088,7 +2082,7 @@ function executeSubscription(
20882082
contextValue,
20892083
operation,
20902084
variableValues,
2091-
shouldProvideSuggestions,
2085+
maskSuggestions,
20922086
} = validatedExecutionArgs;
20932087

20942088
const rootType = schema.getSubscriptionType();
@@ -2105,7 +2099,7 @@ function executeSubscription(
21052099
variableValues,
21062100
rootType,
21072101
operation,
2108-
shouldProvideSuggestions,
2102+
maskSuggestions,
21092103
);
21102104

21112105
const firstRootField = groupedFieldSet.entries().next().value as [
@@ -2142,8 +2136,8 @@ function executeSubscription(
21422136
const args = getArgumentValues(
21432137
fieldDef,
21442138
fieldNodes[0],
2145-
validatedExecutionArgs.shouldProvideSuggestions,
21462139
variableValues,
2140+
maskSuggestions,
21472141
);
21482142

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

0 commit comments

Comments
 (0)