Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fragmentArguments): arguments on directives for nested fields #4180

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,20 @@ describe('Execute: Handles inputs', () => {
});
});

it('when argument passed to a directive on a nested field', () => {
const result = executeQueryWithFragmentArguments(`
query {
...a(value: true)
}
fragment a($value: Boolean!) on TestType {
nested { echo(input: "echo") @skip(if: $value) }
}
`);
expect(result).to.deep.equal({
data: { nested: {} },
});
});

it('when a nullable argument to a directive with a field default is not provided and shadowed by an operation variable', () => {
// this test uses the @defer directive and incremental delivery because the `if` argument for skip/include have no field defaults
const document = parse(
Expand Down
11 changes: 6 additions & 5 deletions src/execution/collectFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ interface CollectFieldsContext {
schema: GraphQLSchema;
fragments: ObjMap<FragmentDetails>;
variableValues: { [variable: string]: unknown };
fragmentVariableValues?: FragmentVariables;
operation: OperationDefinitionNode;
runtimeType: GraphQLObjectType;
visitedFragmentNames: Set<string>;
Expand Down Expand Up @@ -135,14 +134,16 @@ export function collectSubfields(
const newDeferUsages: Array<DeferUsage> = [];

for (const fieldDetail of fieldGroup) {
const node = fieldDetail.node;
if (node.selectionSet) {
const selectionSet = fieldDetail.node.selectionSet;
if (selectionSet) {
const { deferUsage, fragmentVariables } = fieldDetail;
collectFieldsImpl(
context,
node.selectionSet,
selectionSet,
subGroupedFieldSet,
newDeferUsages,
fieldDetail.deferUsage,
deferUsage,
fragmentVariables,
);
}
}
Expand Down
Loading