Skip to content

Fix QueryContext<T> dropping sort fields after a nested object field - #10501

Merged
glen-84 merged 1 commit into
mainfrom
gai/query-context-sort-after-nested-field
Oct 7, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/query-context-sort-after-nested-field

Conversation

@glen-84

@glen-84 glen-84 commented Oct 7, 2026

Copy link
Copy Markdown
Member

Summary

  • QueryContext<T>.Sorting now contains every field of the order argument 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.
  • The formatter behind 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

  • New SortingContextTests cases 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.Tests passes.
  • Every test in Data.Tests and Data.PostgreSQL.Tests passes, which covers QueryContext sorting against PostgreSQL.

Closes #10489

Copilot AI lite review requested due to automatic review settings October 7, 2026 08:50

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.

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.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Patch coverage

83.3% of changed lines covered (5/6)

File Covered Changed Patch %
…/HotChocolate/Data/src/Data/Sorting/Context/SortingContext.cs 5 6 83.3% 🟡
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)

@glen-84
glen-84 merged commit f7b84f2 into main Oct 7, 2026
159 checks passed
@glen-84
glen-84 deleted the gai/query-context-sort-after-nested-field branch October 7, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QueryContext<T> drops sort fields that come after a nested object field

2 participants