Skip to content

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

Closed
@alvinm84

Description

@alvinm84

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

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions