Created
January 28, 2020 06:14
-
-
Save jelorivera08/51514d05d39fbaf289c58cf692cf9fb1 to your computer and use it in GitHub Desktop.
This file contains 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 createNoteMutation($content: String) { | |
createNote(content: $content) { | |
_id | |
content | |
} | |
} | |
`; | |
function createNoteMutation(content) { | |
const variables = { | |
content | |
}; | |
commitMutation(environment, { | |
mutation, | |
variables, | |
onCompleted: (response, errors) => { | |
console.log('Response received from server.'); | |
}, | |
updater: store => { | |
const payload = store.getRootField('createNote'); | |
const root = store.getRoot(); | |
const notes = root.getLinkedRecords('notes'); | |
const newNotes = [...notes, payload]; | |
root.setLinkedRecords(newNotes, 'notes'); | |
}, | |
onError: err => console.error(err) | |
}); | |
} | |
export default createNoteMutation; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment