-
Hi, first - LOVE pothos + prisma. We are using it extensively. ❤️ Thank you @hayes. Question: In pothos, often we query a relation in a way that we want a boolean. For example, we have a To do this, I set up a Is there a way to get Pothos to create these optimal joined Prisma queries, as |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You could do something like this: builder.prismaObject('Post', {
fields: (t) => ({
id: t.exposeID('id'),
title: t.exposeString('title'),
content: t.exposeString('content'),
author: t.relation('author'),
comments: t.relation('comments'),
hasCommented: t.boolean({
select: (args, ctx) => ({
comments: {
where: {
author: {
id: ctx.user!.id,
},
},
take: 1,
// only load the id (optional)
select: {
id: true,
},
},
}),
resolve: (post) => post.comments.length > 0,
}),
}),
}); |
Beta Was this translation helpful? Give feedback.
You could do something like this: