Skip to content

Generic prisma pagination #1206

Answered by hayes
nikatsapien asked this question in Q&A
May 23, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

You can definitely avoid the extra queries. There are a few different options here, but I think the easiest would be to use the queryFromInfo helper to directly load nested selections, and maybe add in the simpleObjects plugin for the extra pagination types

import assert from 'node:assert';
import { User as UserModel } from '@prisma/client';
import { queryFromInfo } from '@pothos/plugin-prisma';

builder.simpleObject('PaginatedUser', {
  description: 'Paginated version of the User type',
  fields: t => ({
    take: t.int(),
    skip: t.int(),
    count: t.int(),
    data: t.field({
      type: User,
    }),
  }),
});

type ResolveUserArgs = {
  query: {}, // { select?: UserSelect, include…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@nikatsapien
Comment options

Answer selected by nikatsapien
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants