Created
January 28, 2020 06:15
-
-
Save jelorivera08/b41b496b367c7e4f127d3bfc947cadd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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