fentalyn
fentalyn

Reputation: 79

Prisma 2: How to paginate fields of a .findUnique() query?

enter image description here

Description: I have a seeProfile resolver, which gives back a profile of a particular user. This user has a photos array and I want to paginate these photos and I can't figure out how. I have a workaround but I'd like to know a way - shall it exist - to paginate a field of this one user.

Workaround: I can simply make a resolver for fetching pictures for a particular user with .findMany() and paginate them with take: and skip: . But then I make two queries instead of one. So, if anyone knows a way to paginate the photos inside findUnique query, please let me know, thanks!

Upvotes: 2

Views: 560

Answers (1)

Tasin Ishmam
Tasin Ishmam

Reputation: 7278

Unfortunately, there's no way as of now to implement pagination inside the include relation in Prisma.

You will have to make two separate queries with Prisma, as you described in your workaround:

  1. One findUnique query to fetch the user records.
  2. One findMany query to fetch the approrpriate photo records.

I can simply make a resolver for fetching pictures for a particular user.

Perhaps it just makes sense to do both queries in the same resolver, to avoid two requests to the API.

Upvotes: 2

Related Questions