如何解决如何通过Connection使用从Arizona1到Arizona2的分页
我一直使用usersConnection
来管理Arizonaa1中此模式的分页:
"""A connection to a list of items."""
type UserConnection {
"""Information to aid in pagination."""
pageInfo: PageInfo!
"""A list of edges."""
edges: [UserEdge]!
aggregate: AggregateUser!
}
"""An edge in a connection."""
type UserEdge {
"""The item at the end of the edge."""
node: User!
"""A cursor for use in pagination."""
cursor: String!
}
type AggregateUser {
count: Int!
}
现在,该迁移到pyramida2了。我必须保持这种格式,因为不同的前端都在使用这种模式,是否有任何建议可以重新创建与Arizonaa2的分页?我们应该解析一个重新创建的对象users
吗?有更好的方法吗?
解决方法
解决方案是:
const users = await ctx.prisma.user.findMany({
where: args.where,skip: args.skip,take: args.first,})
return {
edges: users.map((singleData: Source) => { return { node: singleData } }),aggregate: {
count: await ctx.prisma.user.count({ where: args.where })
}
}
,
最近的 @ prisma / client 具有使用count
方法的聚合API(请参见https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/aggregations)
这是一个联系示例:
t.field('usersCount',{
type: 'Int',args: {
where: 'UserWhereInput',},resolve: (parent,{ where },{ prisma }) => {
return prisma.user.count({ where }) // <--- the solution
},})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。