halborg
09/06/2018, 1:03 PMErrorname
09/06/2018, 1:29 PMtype User {
posts: PaginatedPosts
}
type Post {
id: ID! @unique
title: String!
}
type PaginatedPosts {
nodes: [Post!]!
meta: PaginationMeta!
}
type PaginationMeta {
nodeCount: Int!
pageCount: Int!
pageCurrent: Int!
nodesPerPage: Int!
}
type Query {
user(id: ID!): User!
}
Resolvers:
{
Query: {
users: async (_, args, ctx, info) => ctx.prisma.query.user({where: {id: $id}},info)
},
PaginatedPosts: {
posts: (parent, args, ctx, info) => ctx.prisma.query.posts(args, info),
meta: async (parent, {first, skip}, ctx, info) => {
const connection = await ctx.prisma.query.postsConnection(args, '{ aggregate { count } }')
const count = connection.aggregate.count
return {
nodeCount: count,
pageCount: Math.ceil(count/first),
pageCurrent: skip/first + 1,
nodesPerPage: first
}
}
}
}
I did something like this (but not exactly) in one of my project.
Let me know if this works !
(Also posted this on the forum!)Jared
09/06/2018, 1:41 PMquery fetchClients(
$where: ClientWhereInput
$orderBy: ClientOrderByInput
$first: Int
$skip: Int
) {
clients(where: $where, orderBy: $orderBy, first: $first, skip: $skip) {
id
name
email
}
clientsConnection(where: $where, orderBy: $orderBy, first: $first, skip: $skip) {
aggregate {
count
}
}
}
we then manage the pagination buttons in the front-end using ant.design.halborg
09/06/2018, 1:43 PMclients
is not nested under another object, i.e. {company { clients } }
Jared
09/06/2018, 1:50 PMhalborg
09/06/2018, 1:51 PM