How to return a string after performing a mutation

prisma

#1

I have this mutation I want to return a success message once it is executed:

async attending (parent, { id }, ctx, info) {
    const userId = getUserId(ctx)

    const eventExists = await ctx.db.exists.Event({
      id
    })

    if (!eventExists) {
      throw new Error('Sorry, event not found!')
    }

    await ctx.db.mutation.updateEvent(
      {
        where: {
          id
        },
        data: {
          participants: {
            connect: {
              id: userId
            }
          }
        }
      },
      info
    )

    return `You're attending this event!`
  }

And mutation is defined as:

type Mutation {
  attending(id: ID!): String!
}

But I keep getting this error:

"Field \"updateEvent\" of type \"Event\" must have a selection of subfields. Did you mean \"updateEvent { ... }\"?",

#2

The error message is unrelated to your attending resolver. Looks like your updateEvent resolver is causing the issue.


#3

The problem is that your query looks like this:

mutation {
  attending(id: "abc")
}

You are passing the info object into updateEvent, but they are not “compatible”.

Remove the info object that you pass into updateEvent to fix this.


#4

Ignore my answer and see Nilan’s response. He’s right :roll_eyes: