Repository navigation
Fix QueryContext<T> dropping sort fields after a nested object field - #10501
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review comments remain, and regression coverage is included.
Review effort: Lite
Findings: None
What changed in this PR
Fixes nested sorting so fields following nested object fields are preserved in QueryContext<T>.
Changes:
- Corrects field and type-stack handling during sort-definition formatting.
- Adds regression tests for nested, list, duplicate-name, and deeper nested sorting.
| File | Summary |
|---|---|
src/HotChocolate/Data/test/Data.Sorting.Tests/Context/SortingContextTests.cs |
Adds regression coverage for affected sorting shapes. |
src/HotChocolate/Data/src/Data/Sorting/Context/SortingContext.cs |
Preserves resolved fields across nested formatter traversal. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Patch coverage83.3% of changed lines covered (5/6)
Uncovered changed lines (JSON){
"sha": "14b7f3e28722de040fbf06ceef1f4b79e1bf16e4",
"files": [
{ "path": "src/HotChocolate/Data/src/Data/Sorting/Context/SortingContext.cs", "ranges": [[162, 162]] }
]
}Project coverage: 58.5% (313849/536121 lines) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
QueryContext<T>.Sortingnow contains every field of theorderargument when a field follows a nested object field, such as{ author: { name: ASC }, title: ASC }, the list form[{ author: { name: ASC } }, { title: ASC }], or the same shape one level deeper. Those fields were dropped without an error, and a field sharing a name with one inside the nested object ({ author: { id: ASC }, id: ASC }) threw.ISortingContext.AsSortDefinition<T>()resolved each field a second time when leaving it, against the nested object's type, so that type was never popped and every later field was looked up on it. It now resolves the field once on entry and reuses it on leave.Test plan
SortingContextTestscases assert the sort definition for each of those shapes, plus a scalar field before a nested object. All of them except the scalar-first case fail without the fix.Data.Sorting.Testspasses.Data.TestsandData.PostgreSQL.Testspasses, which coversQueryContextsorting against PostgreSQL.Closes #10489