How to do cursor based pagination? #5016
-
I am trying to get cursor based pagination working, like https://chillicream.com/docs/hotchocolate/fetching-data/pagination/#cursor-pagination. But the result is always offset pagination. Given this code: public class User
{
public string Id { get; set; } = default!;
public string Name { get; set; } = default!;
}
public class Query
{
[UsePaging, UseSorting]
public IQueryable<User> GetUsers([Service(ServiceKind.Synchronized)] QueryDbContext db)
{
return db.User;
}
}
public class QueryDbContext : DbContext // This is NOT EFCore, but custom built, with a custom QueryProvider
{
public DbSet<User> User { get; } = default!;
}
var services = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
var builder = services
.AddGraphQL()
.AddQueryType<Query>()
.AddQueryableCursorPagingProvider(defaultProvider: true) // just trying to get it working
//.AddProjections()
//.AddFiltering()
.AddSorting()
;
services.AddScoped<QueryDbContext>(); client query: { users(after: "....", order: { name: ASC, id: ASC }) { pageInfo { hasNextPage, hasPreviousPage, startCursor, endCursor }, nodes { id, name } } } This adds an unwanted .Skip(11) on the IQueryable. How do I trigger 'Cursor Pagination' like https://chillicream.com/docs/hotchocolate/fetching-data/pagination/#cursor-pagination ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
FYI: I could not find a built-in solution for this way of paging, so I ended up with a custom made |
Beta Was this translation helpful? Give feedback.
FYI: I could not find a built-in solution for this way of paging, so I ended up with a custom made
CursorPagingProvider
andCursorPagingHandler
. Was also the best solution for me; this way I could use Tuple compare in my custom made Entity Framework for best performance using PostgreSQL.