Product
Hot Chocolate
Version
16.5.1
Link to minimal reproduction
https://github.com/rutgersc/hotchocolate-querycontext-repro/blob/sort-drop-16/SortDropAfterNestedObjectTests.cs
Steps to reproduce
See repro link above.
public class Item { public int Id; public string Name; public int Position; public Category Category; }
public class Category { public string Name; }
[UseSorting]
public List<Item> GetItems(QueryContext<Item> context)
=> items.AsQueryable().With(context).ToList();
items(order: { category: { name: ASC }, position: ASC }) {
id
}
QueryContext<Item>.Sorting contains only category.name. position is missing, so rows with the same category name come back unsorted.
Without QueryContext, with [UseSorting] applying the same order argument to a returned IQueryable<>, both fields are sorted:
[UseSorting]
public IQueryable<Item> GetItems()
=> items.AsQueryable();
This querycontext test fails: https://github.com/rutgersc/hotchocolate-querycontext-repro/blob/sort-drop-16/SortDropAfterNestedObjectTests.cs#L84
position is also dropped:
- as a second list item:
[{ category: { name: ASC } }, { position: ASC }]
- one level down:
{ item: { category: { name: ASC }, position: ASC } }
It works when position comes first: { position: ASC, category: { name: ASC } }.
What is expected?
Similar to #9066 and #9111, QueryContext<>.Sorting should contain the same sort as [UseSorting] applies without QueryContext: category.name, then position.
What is actually happening?
position is dropped without an error, so the result is in the wrong order.
This is the shape of #8191. #8356 fixed the crash, but its test (author: { name: ASC, age: ASC }, title: DESC) has a unique author name per book, so it still passes when title is dropped.
The crash from #8191 also still happens when the field after the nested object has the same name as a field inside it: { category: { name: ASC }, name: ASC } (see log output).
Relevant log output
Property 'System.String Name' is not defined for type 'HotChocolateSortNullMemberRepro.Item' (Parameter 'property')
at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)
at HotChocolate.Data.Sorting.SortingContext.SortDefinitionFormatter.CreateSelector(Expression parent, MemberInfo member)
at HotChocolate.Data.Sorting.SortingContext.SortDefinitionFormatter.Enter(ObjectFieldNode node, Context context)
at HotChocolate.Language.Visitors.SyntaxWalker`1.Enter(ISyntaxNode node, TContext context)
at HotChocolate.Language.Visitors.SyntaxVisitor`1.Visit[TNode,TParent](TNode node, TParent parent, TContext context)
at HotChocolate.Language.Visitors.SyntaxVisitor`1.VisitChildren(ObjectValueNode node, TContext context)
at HotChocolate.Language.Visitors.SyntaxVisitor`1.VisitChildren(ISyntaxNode node, TContext context)
at HotChocolate.Language.Visitors.SyntaxVisitor`1.Visit[TNode,TParent](TNode node, TParent parent, TContext context)
at HotChocolate.Language.Visitors.SyntaxVisitor`1.Visit(ISyntaxNode node, TContext context)
at HotChocolate.Data.Sorting.SortingContext.SortDefinitionFormatter.Rewrite(IValueNode node, IType type, Expression parameter)
at HotChocolate.Data.Sorting.SortingContext.AsSortDefinition[T]()
at HotChocolate.Data.QueryContextParameterExpressionBuilder.CreateQueryContext[T](IResolverContext context)
Additional context
No response
Product
Hot Chocolate
Version
16.5.1
Link to minimal reproduction
https://github.com/rutgersc/hotchocolate-querycontext-repro/blob/sort-drop-16/SortDropAfterNestedObjectTests.cs
Steps to reproduce
See repro link above.
QueryContext<Item>.Sortingcontains onlycategory.name.positionis missing, so rows with the same category name come back unsorted.Without QueryContext, with
[UseSorting]applying the same order argument to a returnedIQueryable<>, both fields are sorted:This querycontext test fails: https://github.com/rutgersc/hotchocolate-querycontext-repro/blob/sort-drop-16/SortDropAfterNestedObjectTests.cs#L84
positionis also dropped:[{ category: { name: ASC } }, { position: ASC }]{ item: { category: { name: ASC }, position: ASC } }It works when
positioncomes first:{ position: ASC, category: { name: ASC } }.What is expected?
Similar to #9066 and #9111,
QueryContext<>.Sortingshould contain the same sort as[UseSorting]applies without QueryContext:category.name, thenposition.What is actually happening?
positionis dropped without an error, so the result is in the wrong order.This is the shape of #8191. #8356 fixed the crash, but its test (
author: { name: ASC, age: ASC }, title: DESC) has a unique author name per book, so it still passes whentitleis dropped.The crash from #8191 also still happens when the field after the nested object has the same name as a field inside it:
{ category: { name: ASC }, name: ASC }(see log output).Relevant log output
Additional context
No response