Apply pagination, filtering, sorting, projections in repository when using HotChocolate

43 views Asked by At

When looking at the HotChocolate documentation e.g. for projection, the projection is applied on IQueryable:

public class Query
{
    [UseProjection]
    public IQueryable<User> GetUsers([Service] IUserRepository repository)
        => repository.GetUsers();
}

However I want to use a repository and the repository should return the final result including pagination, filtering, sorting, projections instead of an IQueryable. So code in the end should be something like this:

public class Query
{
    [UsePaging]
    [UseProjection]
    [UseFiltering]
    [UseSorting]
    public IEnumerable<User> GetUsers([Service] IUserRepository repository)
        // idea: pass on pagination, filtering, sorting, projections to repository,
        // so repository can apply these internally
        // -> a) how to obtain those "properties" from the attributes?
        // -> b) how to apply them in the repository?
        => repository.GetUsers(pagination, filtering, sorting, projections);
}

How can that be done?

0

There are 0 answers