Created
January 26, 2019 00:06
-
-
Save scottdomes/c77fe9636b449f24d3bacb2922c1f87e 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 { GET_CONTACTS } from './query'; | |
const updateLocalStore = (cache, { data: { createContact } }) => { | |
const oldContacts = cache.readQuery({ | |
query: GET_CONTACTS | |
}).viewer.allContacts.edges; | |
cache.writeQuery({ | |
query: GET_CONTACTS, | |
data: { | |
viewer: { | |
__typename: 'Viewer', | |
allContacts: { | |
__typename: 'ContactConnection', | |
edges: oldContacts.concat([createContact.contactEdge]) | |
} | |
} | |
} | |
}); | |
}; | |
export default updateLocalStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment