The GraphQL updatePost mutation

A mutation is always located at two points in our code. One part is written inside of our GraphQL API in the back end, and the other one is written in our front end code.

We should start with the implementation on the back end side, as follows:

  1. There is a new mutation that we need to insert into our schema, as follows:
updatePost (  post: PostInput!  postId: Int!): Post
  1. Once it is inside of our schema, the implementation to execute the mutation will follow. Copy the following code over to the resolvers.js file, in the RootMutation field:
updatePost(root, { post, postId }, context) {  return Post.update({    ...post,  },  {    where: {      id: postId    }  }).then((rows) => {    if(rows[0] === 1) {      logger.log({ level: 'info', ...

Get Hands-On Full-Stack Web Development with GraphQL and React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.