Skip to content

Commit 47ff0fb

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

File tree

4 files changed

+65
-24
lines changed

4 files changed

+65
-24
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: 34 additions & 6 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,6 +197,7 @@ function collectFieldsImpl(
188197
variableValues,
189198
selection,
190199
deferUsage,
200+
context.localVariableValues,
191201
);
192202

193203
if (!newDeferUsage) {
@@ -219,12 +229,17 @@ function collectFieldsImpl(
219229
variableValues,
220230
selection,
221231
deferUsage,
232+
context.localVariableValues,
222233
);
223234

224235
if (
225236
!newDeferUsage &&
226237
(visitedFragmentNames.has(fragmentName) ||
227-
!shouldIncludeNode(variableValues, selection))
238+
!shouldIncludeNode(
239+
variableValues,
240+
selection,
241+
context.localVariableValues,
242+
))
228243
) {
229244
continue;
230245
}
@@ -291,8 +306,14 @@ function getDeferUsage(
291306
variableValues: { [variable: string]: unknown },
292307
node: FragmentSpreadNode | InlineFragmentNode,
293308
parentDeferUsage: DeferUsage | undefined,
309+
fragmentVariableValues: { [variable: string]: unknown } | undefined,
294310
): DeferUsage | undefined {
295-
const defer = getDirectiveValues(GraphQLDeferDirective, node, variableValues);
311+
const defer = getDirectiveValues(
312+
GraphQLDeferDirective,
313+
node,
314+
variableValues,
315+
fragmentVariableValues,
316+
);
296317

297318
if (!defer) {
298319
return;
@@ -320,8 +341,14 @@ function getDeferUsage(
320341
function shouldIncludeNode(
321342
variableValues: { [variable: string]: unknown },
322343
node: FragmentSpreadNode | FieldNode | InlineFragmentNode,
344+
fragmentVariableValues: { [variable: string]: unknown } | undefined,
323345
): boolean {
324-
const skip = getDirectiveValues(GraphQLSkipDirective, node, variableValues);
346+
const skip = getDirectiveValues(
347+
GraphQLSkipDirective,
348+
node,
349+
variableValues,
350+
fragmentVariableValues,
351+
);
325352
if (skip?.if === true) {
326353
return false;
327354
}
@@ -330,6 +357,7 @@ function shouldIncludeNode(
330357
GraphQLIncludeDirective,
331358
node,
332359
variableValues,
360+
fragmentVariableValues,
333361
);
334362
if (include?.if === false) {
335363
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,18 @@ 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(
347+
directiveNode,
348+
directiveDef.args,
349+
variableValues,
350+
fragmentVariables,
351+
);
346352
}
347353
}

0 commit comments

Comments
 (0)