Skip to content

Instantly share code, notes, and snippets.

@scottdomes
Created January 26, 2019 00:06
Show Gist options
  • Save scottdomes/c77fe9636b449f24d3bacb2922c1f87e to your computer and use it in GitHub Desktop.
Save scottdomes/c77fe9636b449f24d3bacb2922c1f87e to your computer and use it in GitHub Desktop.
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