Skip to content

Sorting by a nested property of member object followed by a parent object property throws error #8191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alvinm84 opened this issue Mar 27, 2025 · 0 comments

Comments

@alvinm84
Copy link

Product

Hot Chocolate

Version

15.1.1

Link to minimal reproduction

https://github.com/alvinm84/HC-005

Steps to reproduce

Example resolver:

[UsePaging] 
[UseFiltering] 
[UseSorting] 
public static async Task<Connection<Product>> GetProductsAsync(
    QueryContext<Product> context,
    PagingArguments pagingArgs,
    ProductService productService, 
    CancellationToken cancellationToken)
    => await productService.GetProductsAsync(context, pagingArgs, cancellationToken).ToConnectionAsync();

Example query with nested property of a member object and a parent object's property:

query products {
  products(order: { [type: {name: ASC} name: ASC]  }) {
    edges {
      node {
        id
        name
        productType {
          id
          name
        }...
}

Error message:

"message": "Property 'eShop.Catalog.Models.ProductType Type' is not defined for type 'eShop.Catalog.Models.Brand' (Parameter 'property')"

Example query with nested property from different member objects, also throws similar error:

query products {
  products(order: { brand: {name: ASC } type: {name: ASC} }) {
    edges {
      node {
       ....
        }
}

Error message:

"message": "Property 'eShop.Catalog.Models.ProductType Type' is not defined for type 'eShop.Catalog.Models.Brand' (Parameter 'property')"

What is expected?

Sorting by a nested member object property followed by a parent object property, and/or by properties from a nested member object works.

What is actually happening?

Sorting by a nested member object property followed by a parent object property, and/or by properties from a nested member object throws error.
However, if sorting by starts with the parent object property and followed by nested member object property, it works fine.
Example query:

query products {
  products(order: { name: ASC type: {name: ASC}  }) {
    edges {
      node {
        id
        name
        productType {
          id
          name
        }...
}
  

Relevant log output

at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)\r\n   at HotChocolate.Data.Sorting.SortingContext.SortDefinitionFormatter.Enter(ObjectFieldNode node, Context context)\r\n   at HotChocolate.Language.Visitors.SyntaxWalker`1.Enter(ISyntaxNode node, TContext context)\r\n   at HotChocolate.Language.Visitors.SyntaxVisitor`1.Visit[TNode,TParent](TNode node, TParent parent, TContext context)\r\n   at HotChocolate.Language.Visitors.SyntaxVisitor`1.VisitChildren(ObjectValueNode node, TContext context)\r\n   at HotChocolate.Language.Visitors.SyntaxVisitor`1.VisitChildren(ISyntaxNode node, TContext context)\r\n   at HotChocolate.Language.Visitors.SyntaxVisitor`1.Visit[TNode,TParent](TNode node, TParent parent, TContext context)\r\n   at HotChocolate.Language.Visitors.SyntaxVisitor`1.VisitChildren(ListValueNode node, TContext context)\r\n   at HotChocolate.Language.Visitors.SyntaxVisitor`1.VisitChildren(ISyntaxNode node, TContext context)\r\n   at HotChocolate.Language.Visitors.SyntaxVisitor`1.Visit[TNode,TParent](TNode node, TParent parent, TContext context)\r\n   at HotChocolate.Language.Visitors.SyntaxVisitor`1.Visit(ISyntaxNode node, TContext context)\r\n   at HotChocolate.Data.Sorting.SortingContext.SortDefinitionFormatter.Rewrite[T](IValueNode node, IType type, Expression parameter)\r\n   at HotChocolate.Data.Sorting.SortingContext.AsSortDefinition[T]()\r\n   at HotChocolate.Data.QueryContextParameterExpressionBuilder.CreateQueryContext[T](IResolverContext context)\r\n   at lambda_method13(Closure, IResolverContext)\r\n   at HotChocolate.Types.Helpers.FieldMiddlewareCompiler.<>c__DisplayClass9_0.<<CreateResolverMiddleware>b__0>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.Types.UnwrapFieldMiddlewareHelper.<>c__DisplayClass0_1.<<CreateDataMiddleware>b__1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.Types.UnwrapFieldMiddlewareHelper.<>c__DisplayClass0_1.<<CreateDataMiddleware>b__1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n   at HotChocolate.Types.Pagination.PagingMiddleware.InvokeAsync(IMiddlewareContext context)\r\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)\r\n   at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)

Additional context

The same issue is reproduceable in v15.1.2-p.1

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

No branches or pull requests

1 participant