2

I am switching to Prisma2 using nexus and cannot find a good way to implement pagination - a skip type will work fine. I could find a good way to implement it on the array, so what I ended up is added a computed field total on the type.

export const User = objectType({
name: 'User',
 definition(t) {
t.model.id()
t.model.name()
...
t.field('total', {
  type: 'Int',
  resolve: async (parent, args, ctx, info) => {
    let users = await ctx.photon.users.findMany()
    return users.length
  },
})

It's usable, but I am sure that there is a better way... can anyone give me a hint?

Svitlana
  • 2,324
  • 4
  • 22
  • 31

1 Answers1

2

Latest prisma2 has count().

prisma.user.count() gives total number of users and then number of pages is count/limit.

source: https://github.com/prisma/prisma2/blob/master/docs/prisma-client-js/api.md

SaiNageswar S
  • 1,203
  • 13
  • 22