Repository navigation
Fix GraphQL fragment selection dropping trailing fields - #3862
Joel Town Road (hippi345) wants to merge 4 commits into
Conversation
AddGraphQLFields used return after expanding a fragment spread or inline fragment, which exited the selection loop and omitted later fields. Continue to the next selection instead.
HTTP fragment queries do not hit AddGraphQLFields' fragment branches on Hot Chocolate 16, so keep only the unit test that covers the loop.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
🟢 Approval recommended
The focused control-flow fix preserves trailing selections, and the regression test directly covers the failure.
No open issues 🎉
What changed in this PR
Fixes a latent SQL GraphQL selection bug from #3861 that drops fields following fragments.
Changes:
- Continues processing selections after named and inline fragments.
- Adds a direct regression test for fields following an inline fragment, bypassing Hot Chocolate 16’s fragment normalization.
| File | Description |
|---|---|
| src/Service.Tests/UnitTests/SqlQueryStructureHelperTests.cs | Adds regression coverage and supporting metadata setup. |
| src/Core/Resolvers/Sql Query Structures/SqlQueryStructure.cs | Replaces early returns with loop continuation after fragment expansion. |
Review effort: Balanced
Mohit G (gmohit21)
left a comment
There was a problem hiding this comment.
Hi Joel Town Road (@hippi345) , The changes LGTM—the return → continue fix makes sense for both fragment branches. Could you please address the following as well?
- CI validation: I only see the CLA and reviewer-assignment checks on this PR. Could we get the required build and test pipelines running and confirm they pass before merging?
- Named-fragment coverage: Could you add a regression test for a named fragment spread followed by another field, matching the example in #3861? The new test covers inline fragments, but not named spreads. Please verify that the test fails with the original
returnand passes withcontinue, asserting that both the fragment’s fields and the trailing field are included.
Thanks!
Cover the Azure#3861 query shape: a bookFields spread selecting id, followed by title. The test fails if AddGraphQLFields returns after the spread, because the trailing field is omitted from the query columns.
|
The new commit is 8c83517. Fork PRs here don't start the build and test pipelines until a project member comments /azp run. If you can comment /azp run, I'll watch them. Added AddGraphQLFields_ContinuesAfterNamedFragmentSpread for the #3861 shape: ...bookFields selecting id, then title. Both columns have to be present. With the old return the test fails (Expected:<2>. Actual:<1>). With continue it passes. |
Why make this change?
SqlQueryStructure.AddGraphQLFields, expanding a fragment spread or inline fragment usedreturn;, which exits the selectionforeachinstead of moving to the next node.AddGraphQLFieldsruns). The issue was reported on 2.1.5, which uses the same Hot Chocolate version, so the HTTP reproduction may depend on conditions we couldn't recreate. The code bug is real, and the unit test covers the loop.What is this change?
FragmentSpreadorInlineFragment,AddGraphQLFieldscontinues to the next selection instead of returning from the method.AddGraphQLFields_ContinuesAfterInlineFragmentcallsAddGraphQLFieldsdirectly with an inline fragment followed by another field, covering the selection loop.How was this tested?
With the fix reverted (
return;in both fragment branches), the unit test failed because the trailing field was dropped:With
continue;applied:(The 34-test run is
FullyQualifiedName~SqlQueryStructureHelperTests, which includesSqlQueryStructureHelperTestsand nearbyBaseSqlQueryStructureHelperTests.)Sample Request(s)
GraphQL query that would drop trailing fields when AddGraphQLFields receives unexpanded fragments (exercised directly by the unit test):
On current main with Hot Chocolate 16, the engine merges those fragment selections before
AddGraphQLFields, so this HTTP query is not a reproduction. The unit test is the coverage for the loop.This change was prepared with AI assistance. I remain responsible for the contribution and have reviewed it.