Reputation: 181
What's the best way to handle success or error after a mutation?
I'm using React.js and react-router-relay to make graphQL queries and mutations.
Let's say I have a React component performing a Rename mutation. I'd like to have a user callback after the mutation has been done saying
How can I have that kind of callback? And how to handle different error codes?
Upvotes: 3
Views: 961
Reputation: 181
Well! It seems it was as simple as add a callbacks object on the mutation:
var onSuccess = () => {
console.log('Mutation successful!');
};
var onFailure = (`enter code here`transaction) => {
var error = transaction.getError() || new Error('Mutation failed.');
console.error(error);
};
var mutation = new MyMutation({...});
Relay.Store.commitUpdate(mutation, {onFailure, onSuccess});
https://facebook.github.io/relay/docs/api-reference-relay-store.html
Upvotes: 4