Prisma: Asyncronous Extended Fields

Anyone familiar with any better way to accomplish the equivalent of field resolvers with prisma? The Ask I need an async field returned with each user The Scenario Say I want to findMany on users but I want a likeCount and followCount fields returned with each result. The expand api looks to be on the right track but it looks like its unable to perform asynchronous computes for additional fields. Such as if I wanted to add an async field called likeCount to user which would be returned on each user result.
const xprisma = prisma
.$extends({
result: {
user: {
likeCount: {
needs: { id: true },
compute({id}) {
return prisma.likes.count({where: userId: id})
},
},
},
},
})
const xprisma = prisma
.$extends({
result: {
user: {
likeCount: {
needs: { id: true },
compute({id}) {
return prisma.likes.count({where: userId: id})
},
},
},
},
})
I know I can just _count likes on user for this example. This is simplified for an example
0 Replies
No replies yetBe the first to reply to this messageJoin