Skip to content

Commit a8d09ec

Browse files
authored
Fixed issue when sorting by a top-level property after a nested property (#8356)
1 parent 4738de3 commit a8d09ec

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/HotChocolate/Data/src/Data/Sorting/Context/SortingContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ protected override ISyntaxVisitorAction Leave(
196196
else
197197
{
198198
context.Types.Pop();
199+
context.Parents.Pop();
199200
}
200201

201202
return base.Leave(node, context);

src/HotChocolate/Data/test/Data.Sorting.Tests/IntegrationTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task Sorting_Should_Work_When_Nested()
4444

4545
const string query = @"
4646
{
47-
books(order: [{ author: { name: ASC } }]) {
47+
books(order: [{ author: { name: ASC, age: ASC }, title: DESC }]) {
4848
title
4949
author {
5050
name
@@ -75,9 +75,9 @@ public IEnumerable<Foo> Foos() =>
7575
public IEnumerable<Book> GetBooks(QueryContext<Book> queryContext)
7676
=> new[]
7777
{
78-
new Book { Title = "Book5", Author = new Author { Name = "Author6" } },
79-
new Book { Title = "Book7", Author = new Author { Name = "Author17" } },
80-
new Book { Title = "Book1", Author = new Author { Name = "Author5" } }
78+
new Book { Title = "Book5", Author = new Author { Age = 30, Name = "Author6" } },
79+
new Book { Title = "Book7", Author = new Author { Age = 34, Name = "Author17" } },
80+
new Book { Title = "Book1", Author = new Author { Age = 50, Name = "Author5" } }
8181
}
8282
.AsQueryable()
8383
.With(queryContext);
@@ -93,6 +93,8 @@ public class Author
9393
{
9494
public string Name { get; set; } = string.Empty;
9595

96+
public int Age { get; set; }
97+
9698
[UseSorting]
9799
public Book[] Books { get; set; } = [];
98100
}

0 commit comments

Comments
 (0)