Skip to content

Commit

Permalink
fix(fragmentArguments): arguments on directives for nested fields (gr…
Browse files Browse the repository at this point in the history
…aphql#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!
  • Loading branch information
yaacovCR authored Sep 6, 2024
1 parent 699c1fc commit 1dbdadc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
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

0 comments on commit 1dbdadc

Please sign in to comment.