Skip to content

Commit 1dbdadc

Browse files
authored
fix(fragmentArguments): arguments on directives for nested fields (#4180)
fixes up just merged #4015 this was actually intended to be in #4015, but due to branch confusion not originally included now we also have a test!
1 parent 699c1fc commit 1dbdadc

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/execution/__tests__/variables-test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,20 @@ describe('Execute: Handles inputs', () => {
15151515
});
15161516
});
15171517

1518+
it('when argument passed to a directive on a nested field', () => {
1519+
const result = executeQueryWithFragmentArguments(`
1520+
query {
1521+
...a(value: true)
1522+
}
1523+
fragment a($value: Boolean!) on TestType {
1524+
nested { echo(input: "echo") @skip(if: $value) }
1525+
}
1526+
`);
1527+
expect(result).to.deep.equal({
1528+
data: { nested: {} },
1529+
});
1530+
});
1531+
15181532
it('when a nullable argument to a directive with a field default is not provided and shadowed by an operation variable', () => {
15191533
// this test uses the @defer directive and incremental delivery because the `if` argument for skip/include have no field defaults
15201534
const document = parse(

src/execution/collectFields.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ interface CollectFieldsContext {
5656
schema: GraphQLSchema;
5757
fragments: ObjMap<FragmentDetails>;
5858
variableValues: { [variable: string]: unknown };
59-
fragmentVariableValues?: FragmentVariables;
6059
operation: OperationDefinitionNode;
6160
runtimeType: GraphQLObjectType;
6261
visitedFragmentNames: Set<string>;
@@ -135,14 +134,16 @@ export function collectSubfields(
135134
const newDeferUsages: Array<DeferUsage> = [];
136135

137136
for (const fieldDetail of fieldGroup) {
138-
const node = fieldDetail.node;
139-
if (node.selectionSet) {
137+
const selectionSet = fieldDetail.node.selectionSet;
138+
if (selectionSet) {
139+
const { deferUsage, fragmentVariables } = fieldDetail;
140140
collectFieldsImpl(
141141
context,
142-
node.selectionSet,
142+
selectionSet,
143143
subGroupedFieldSet,
144144
newDeferUsages,
145-
fieldDetail.deferUsage,
145+
deferUsage,
146+
fragmentVariables,
146147
);
147148
}
148149
}

0 commit comments

Comments
 (0)