Skip to content

Fix GraphQL fragment selection dropping trailing fields - #3862

Open
Joel Town Road (hippi345) wants to merge 2 commits into
Azure:mainfrom
hippi345:fix/3861-fragment-continue
Open

Joel Town Road (hippi345) wants to merge 2 commits into
Azure:mainfrom
hippi345:fix/3861-fragment-continue

Conversation

@hippi345

@hippi345 Joel Town Road (hippi345) commented Oct 17, 2026 •

Copy link
Copy Markdown

Why make this change?

  • Fixes [Bug]: GraphQL fields listed after a fragment spread are silently dropped #3861
    • In SqlQueryStructure.AddGraphQLFields, expanding a fragment spread or inline fragment used return;, which exits the selection foreach instead of moving to the next node.
    • HTTP GraphQL queries on current main do not reproduce this in our testing (Hot Chocolate 16 appears to merge fragment selections before AddGraphQLFields runs). 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?

  • After expanding a FragmentSpread or InlineFragment, AddGraphQLFields continues to the next selection instead of returning from the method.
  • Unit test AddGraphQLFields_ContinuesAfterInlineFragment calls AddGraphQLFields directly with an inline fragment followed by another field, covering the selection loop.

How was this tested?

  • Integration Tests
  • Unit Tests
dotnet test src/Service.Tests/Azure.DataApiBuilder.Service.Tests.csproj \
  --filter "FullyQualifiedName~AddGraphQLFields_ContinuesAfterInlineFragment" \
  --configuration Debug

dotnet test src/Service.Tests/Azure.DataApiBuilder.Service.Tests.csproj \
  --filter "FullyQualifiedName~SqlQueryStructureHelperTests" \
  --configuration Debug

With the fix reverted (return; in both fragment branches), the unit test failed because the trailing field was dropped:

Failed AddGraphQLFields_ContinuesAfterInlineFragment [103 ms]
Error Message:
 CollectionAssert.AreEquivalent failed. The number of elements in the collections do not match. Expected:<2>. Actual:<1>.

Test Run Failed.
Total tests: 1
     Failed: 1

With continue; applied:

Passed AddGraphQLFields_ContinuesAfterInlineFragment [5 ms]
...
Test Run Successful.
Total tests: 34
     Passed: 34

(The 34-test run is FullyQualifiedName~SqlQueryStructureHelperTests, which includes SqlQueryStructureHelperTests and nearby BaseSqlQueryStructureHelperTests.)

Sample Request(s)

GraphQL query that would drop trailing fields when AddGraphQLFields receives unexpanded fragments (exercised directly by the unit test):

query {
  book_by_pk(id: 1) {
    ...bookFields
    title
    publishers { name }
  }
}

fragment bookFields on book { id }

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.

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

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@hippi345

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GraphQL fields listed after a fragment spread are silently dropped

2 participants