Skip to content

How to get total edge count with prismaNode and prismaConnection? #343

Answered by hayes
ricardo-valero asked this question in Q&A
Discussion options

You must be logged in to vote

If you don't need to arguments for the field, this is pretty easy:

builder.queryFields((t) => ({
  posts: t.prismaConnection(
    {
      type: 'Post',
      cursor: 'id',
      resolve: (query) =>
        db.post.findMany({
          orderBy: { createdAt: 'desc' },
          ...query,
        }),
    },
    {
      fields: (t) => ({
        totalCount: t.int({
          resolve: () => db.post.count(),
        }),
      }),
    },
  ),
}));

Unfortunately the arguments for the prismaConnection field are not directly available in fields defined on the connection object. If you need to access arguments to get the count, this won't work. I can't think of a simple solution currently, and that …

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@hayes
Comment options

@hayes
Comment options

@danieljvdm
Comment options

@hayes
Comment options

@danieljvdm
Comment options

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