Skip to content

Simple question: changing types on the way out #481

Answered by hayes
ajoslin asked this question in Q&A
Discussion options

You must be logged in to vote

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,
    }),
  }),
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hayes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants