Skip to content

Commit b1db44f

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

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/execution/__tests__/variables-test.ts

Lines changed: 14 additions & 0 deletions
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
/* TODO: add back when @defer and @stream are supported
15191533
it('when a nullable argument to a directive with a field default is not provided and shadowed by an operation variable', () => {
15201534
// this test uses the @defer directive and incremental delivery because the `if` argument for skip/include have no field defaults

src/execution/collectFields.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ interface CollectFieldsContext {
4646
schema: GraphQLSchema;
4747
fragments: ObjMap<FragmentDetails>;
4848
variableValues: { [variable: string]: unknown };
49-
fragmentVariableValues?: FragmentVariables;
5049
runtimeType: GraphQLObjectType;
5150
visitedFragmentNames: Set<string>;
5251
}
@@ -107,9 +106,15 @@ export function collectSubfields(
107106
const subGroupedFieldSet = new AccumulatorMap<string, FieldDetails>();
108107

109108
for (const fieldDetail of fieldGroup) {
110-
const node = fieldDetail.node;
111-
if (node.selectionSet) {
112-
collectFieldsImpl(context, node.selectionSet, subGroupedFieldSet);
109+
const selectionSet = fieldDetail.node.selectionSet;
110+
if (selectionSet) {
111+
const { fragmentVariables } = fieldDetail;
112+
collectFieldsImpl(
113+
context,
114+
selectionSet,
115+
subGroupedFieldSet,
116+
fragmentVariables,
117+
);
113118
}
114119
}
115120

0 commit comments

Comments
 (0)