Skip to content

Commit 1d24995

Browse files
committed
Correct test and lint stuff
1 parent 1d120d0 commit 1d24995

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

src/execution/__tests__/variables-test.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { inspect } from '../../jsutils/inspect.js';
77

88
import { GraphQLError } from '../../error/GraphQLError.js';
99

10+
import { DirectiveLocation } from '../../language/directiveLocation.js';
1011
import { Kind } from '../../language/kinds.js';
1112
import { parse } from '../../language/parser.js';
1213

@@ -22,15 +23,15 @@ import {
2223
GraphQLObjectType,
2324
GraphQLScalarType,
2425
} from '../../type/definition.js';
26+
import {
27+
GraphQLDirective,
28+
GraphQLIncludeDirective,
29+
} from '../../type/directives.js';
2530
import { GraphQLBoolean, GraphQLString } from '../../type/scalars.js';
2631
import { GraphQLSchema } from '../../type/schema.js';
2732

28-
import { executeSync } from '../execute.js';
33+
import { executeSync, experimentalExecuteIncrementally } from '../execute.js';
2934
import { getVariableValues } from '../values.js';
30-
import { GraphQLSkipDirective } from '../../type/directives.js';
31-
import { GraphQLIncludeDirective } from '../../type/directives.js';
32-
import { GraphQLDirective } from '../../type/directives.js';
33-
import { DirectiveLocation } from '../../language/directiveLocation.js';
3435

3536
const TestFaultyScalarGraphQLError = new GraphQLError(
3637
'FaultyScalarErrorMessage',
@@ -1498,17 +1499,22 @@ describe('Execute: Handles inputs', () => {
14981499
});
14991500

15001501
it('when a nullable argument to a directive with a field default is not provided and shadowed by an operation variable', () => {
1501-
const result = executeQueryWithFragmentArguments(`
1502-
query($value: Boolean) {
1503-
...a
1504-
}
1505-
fragment a($value: Boolean) on TestType {
1506-
fieldWithNonNullableStringInput @skip(if: $value)
1507-
}
1508-
`);
1509-
expect(result).to.deep.equal({
1510-
data: {},
1511-
});
1502+
// this test uses the @defer directive and incremental delivery because the `if` argument for skip/include have no field defaults
1503+
const document = parse(
1504+
`
1505+
query($shouldDefer: Boolean = false) {
1506+
...a
1507+
}
1508+
fragment a($shouldDefer: Boolean) on TestType {
1509+
... @defer(if: $shouldDefer) {
1510+
fieldWithDefaultArgumentValue
1511+
}
1512+
}
1513+
`,
1514+
{ experimentalFragmentArguments: true },
1515+
);
1516+
const result = experimentalExecuteIncrementally({ schema, document });
1517+
expect(result).to.include.keys('initialResult', 'subsequentResults');
15121518
});
15131519
});
15141520
});

src/execution/collectFields.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,13 @@ function collectFieldsImpl(
164164
for (const selection of selectionSet.selections) {
165165
switch (selection.kind) {
166166
case Kind.FIELD: {
167-
const vars = localVariableValues ?? variableValues;
168-
if (!shouldIncludeNode(vars, selection)) {
167+
if (
168+
!shouldIncludeNode(
169+
variableValues,
170+
selection,
171+
context.localVariableValues
172+
)
173+
) {
169174
continue;
170175
}
171176
groupedFieldSet.add(getFieldEntryKey(selection), {
@@ -177,7 +182,11 @@ function collectFieldsImpl(
177182
}
178183
case Kind.INLINE_FRAGMENT: {
179184
if (
180-
!shouldIncludeNode(variableValues, selection) ||
185+
!shouldIncludeNode(
186+
variableValues,
187+
selection,
188+
context.localVariableValues
189+
) ||
181190
!doesFragmentConditionMatch(schema, selection, runtimeType)
182191
) {
183192
continue;
@@ -188,8 +197,10 @@ function collectFieldsImpl(
188197
variableValues,
189198
selection,
190199
deferUsage,
200+
context.localVariableValues
191201
);
192202

203+
193204
if (!newDeferUsage) {
194205
collectFieldsImpl(
195206
context,
@@ -219,12 +230,17 @@ function collectFieldsImpl(
219230
variableValues,
220231
selection,
221232
deferUsage,
233+
context.localVariableValues
222234
);
223235

224236
if (
225237
!newDeferUsage &&
226238
(visitedFragmentNames.has(fragmentName) ||
227-
!shouldIncludeNode(variableValues, selection))
239+
!shouldIncludeNode(
240+
variableValues,
241+
selection,
242+
context.localVariableValues
243+
))
228244
) {
229245
continue;
230246
}
@@ -291,8 +307,9 @@ function getDeferUsage(
291307
variableValues: { [variable: string]: unknown },
292308
node: FragmentSpreadNode | InlineFragmentNode,
293309
parentDeferUsage: DeferUsage | undefined,
310+
fragmentVariableValues: { [variable: string]: unknown } | undefined,
294311
): DeferUsage | undefined {
295-
const defer = getDirectiveValues(GraphQLDeferDirective, node, variableValues);
312+
const defer = getDirectiveValues(GraphQLDeferDirective, node, variableValues, fragmentVariableValues);
296313

297314
if (!defer) {
298315
return;
@@ -320,8 +337,9 @@ function getDeferUsage(
320337
function shouldIncludeNode(
321338
variableValues: { [variable: string]: unknown },
322339
node: FragmentSpreadNode | FieldNode | InlineFragmentNode,
323-
): boolean {
324-
const skip = getDirectiveValues(GraphQLSkipDirective, node, variableValues);
340+
fragmentVariableValues: { [variable: string]: unknown } | undefined,
341+
): boolean {
342+
const skip = getDirectiveValues(GraphQLSkipDirective, node, variableValues, fragmentVariableValues);
325343
if (skip?.if === true) {
326344
return false;
327345
}
@@ -330,6 +348,7 @@ function shouldIncludeNode(
330348
GraphQLIncludeDirective,
331349
node,
332350
variableValues,
351+
fragmentVariableValues,
333352
);
334353
if (include?.if === false) {
335354
return false;

src/execution/execute.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ function getStreamUsage(
10291029
const stream = getDirectiveValues(
10301030
GraphQLStreamDirective,
10311031
fieldGroup[0].node,
1032-
fieldGroup[0].fragmentVariableValues ?? exeContext.variableValues,
1032+
exeContext.variableValues,
1033+
fieldGroup[0].fragmentVariableValues
10331034
);
10341035

10351036
if (!stream) {

src/execution/values.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,13 @@ export function getDirectiveValues(
336336
directiveDef: GraphQLDirective,
337337
node: { readonly directives?: ReadonlyArray<DirectiveNode> | undefined },
338338
variableValues?: Maybe<ObjMap<unknown>>,
339+
fragmentVariables?: Maybe<ObjMap<unknown>>,
339340
): undefined | { [argument: string]: unknown } {
340341
const directiveNode = node.directives?.find(
341342
(directive) => directive.name.value === directiveDef.name,
342343
);
343344

344345
if (directiveNode) {
345-
return getArgumentValues(directiveNode, directiveDef.args, variableValues);
346+
return getArgumentValues(directiveNode, directiveDef.args, variableValues, fragmentVariables);
346347
}
347348
}

0 commit comments

Comments
 (0)