How to make a mutation update? ``` async createDr...
# random
p
How to make a mutation update?
Copy code
async createDraft(parent, { title, text }, ctx, info) {
    const userId = getUserId(ctx)
    return ctx.db.mutation.createPost(
      {
        data: {
          title,
          text,
          isPublished: false,
          author: {
            connect: { id: userId },
          },
        },
      },
      info
    )
  },
m
updatePost(...)
?
p
Copy code
async updatePost(parent, { id, text, title }, ctx, info) {
    const userId = getUserId(ctx)
    const postExists = await <http://ctx.db.exists.Post|ctx.db.exists.Post>({
      id,
      author: { id: userId },
    })
    if (!postExists) {
      throw new Error(`Post not found or you're not the author`)
    }

    return ctx.db.mutation.updatePost(
      {
        where: { id },
        data: {
          title,
          text,
          isPublished: true,
          author: {
            connect: { id: userId },
          },
        },
      },
      info,
    )
  },
Thanks, done 😃
👍 1