The Apollo Mutation component

A big part of our main Feed.js file still consists of rendering the real form markup and using the Apollo Mutation component to pass and execute the mutation within the form. We will now separate those parts:

  1. Create a new folder for all your mutations, as follows:
mkdir src/client/components/mutations
  1. Next, we want to outsource the mutation into a special file. To do so, create the addPost.js file, named after the GraphQL mutation itself. Insert the following code:
export default class AddPostMutation extends Component {  state = {    postContent: ''  }  changePostContent = (value) => {    this.setState({postContent: value})  }  render() {    const self = this;    const { children, variables } = this.props; const { postContent ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.