Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jelorivera08/b41b496b367c7e4f127d3bfc947cadd6 to your computer and use it in GitHub Desktop.
Save jelorivera08/b41b496b367c7e4f127d3bfc947cadd6 to your computer and use it in GitHub Desktop.
import { commitMutation, graphql } from 'react-relay';
import environment from '../../../../environment';
const mutation = graphql`
mutation deleteNoteMutation($_id: ID) {
deleteNote(_id: $_id)
}
`;
function deleteNoteMutation(_id) {
const variables = {
_id
};
commitMutation(environment, {
mutation,
variables,
onCompleted: (response, errors) => {
console.log('Response received from server.');
},
updater: store => {
const root = store.getRoot();
const notes = root.getLinkedRecords('notes');
const newNotes = notes.filter(v => v.getValue('_id') !== _id);
root.setLinkedRecords(newNotes, 'notes');
},
onError: err => console.error(err)
});
}
export default deleteNoteMutation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment