2

HotChocolate Version=12.3.2.0

I want to be able to page/filter/sort on nested fields. For example, where user id = 1234, get the user's 1st document set, then the 1st docFile in the document set, ordered by docFile createdDate.

    public class User
    {
        public int Id {get;set}
    
        [UsePaging]
        [UseFiltering]
        [UseSorting]
        public List<Document> Documents { get; set; }
    }
    
    public class Document
    {
        [UsePaging]
        [UseFiltering]
        [UseSorting]
        public List<DocFile> DocFiles { get; set; }
        public User User {get;set;}
    }
    
    public class DocFile
    {
       public string Name {get;set}
       public DateTime CreatedDate {get;set;}
       public Document Document {get;set;}
    }
  


    [UseAppDbContext]
    [UsePaging]
    [UseProjection]
    [UseFiltering]
    [UseSorting]
    public async Task<Connection<User>> GetUsersAsync(
        IResolverContext context,
        [ScopedService] DbContext dbContext,
        CancellationToken cancellationToken
    )
    {
        var dbResult = dbContext.Users.Filter(context).Sort(context).Project(context).ToArray();
        var result = await dbResult.ApplyCursorPaginationAsync(context, cancellationToken);
        return result;
    }

GraphQL Query

  users(
    where: {id: {eq: 1234}} 
  ) {
    nodes {
      documents(first:1){
        id
        files(first:1 order:{createdDate: DESC}) {
          nodes {                 
            name
            createdDate
          }
        }
      }
    }
  }
    

But when I execute the GraphQL query I currently get the following error:

"exceptionType": "InvalidOperationException", "message": "No generic method 'OrderByDescending' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic. "

Any idea on how to do this?

1 Answer 1

0

If the [UseSorting] annotation comes from HotChocolate.Types it's the old way of filtering (uses a different syntax). Then it should be order_by in your query.

Try [HotChocolate.Data.UseSorting] to match your query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.