How do I do a GraphQL mutation callback?
This is how my react component and the mutation looks like:
class CreateAccount extends Component {
constructor () {
super()
this.state = {
username: '',
password: ''
}
}
render () {
return (
// form with input fields; values get stored as state
)
}
_createUser = async () => {
const { username, password } = this.state
await this.props.createUserMutation({
variables: {
username,
password
}
})
}
}
export default compose(
withData,
withApollo,
graphql(
gql`
mutation RootMutationQuery($username: String!, $password: String!) {
createUser(
username: $username,
password: $password,
) {
_id
username
password
}
}
`, { name: 'createUserMutation' }
)
)(CreateAccount)