zenstackhq / zenstack

Fullstack TypeScript toolkit that enhances Prisma ORM with flexible Authorization layer for RBAC/ABAC/PBAC/ReBAC, offering auto-generated type-safe APIs and frontend hooks.
https://zenstack.dev
MIT License
2.07k stars 88 forks source link

Consider to support pagination at react-hooks/trpc-route level #297

Closed ymc9 closed 1 year ago

ymc9 commented 1 year ago

Pagination can be done using Prisma client but it has one drawback: you can't get the total count in the same call with fetching a page.

https://github.com/prisma/prisma/issues/7550

ZenStack can probably makes some improvements here, say by adding a paginate API at the open-api level and corresponding client code generation for react-hooks and trpc-router.

const { paginate } = usePost();

const { data } = paginate({ where: {...}, take: ..., skip: ...});
const { count, items } = data;
ymc9 commented 1 year ago

Also, today react-hooks plugin doesn't generate a count hooks, otherwise it can serve as a workaround for getting totals.

ymc9 commented 1 year ago

Related discussion from discord:

image
ymc9 commented 1 year ago

SWR and Tanstack-Query plugins now generate useInfiniteFindManyXXX hooks.