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 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.