Skip to content

How to create a custom mutation Output with Prisma fields #1032

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

You must be logged in to vote

I'd do something like this:

const User = builder.prismaObject('User', { ... });
const UserAndToken = builder.objectRef<{ token: string, user: User }>('UserAndToken').implement({
  fields: t => ({
    user: t.field({ type: User, resolve: (parent) => parent.user }),
});
builder.mutationFields((t) => ({
  getUserAndToken: t.field({
    type: UserAndToken,
    args: {
      email: t.arg.string({ required: true }),
      password: t.arg.string({ required: true }),
    },
    resolve: async (_root, args, context, info) => {
      // get a query object that includes selections nested inside UserAndToken.user
      const query = queryFromInfo({
        context,
        info,
        path: ['user'],

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by baconcheese113
Comment options

You must be logged in to vote
1 reply
@hayes
Comment options

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