otissv
08/31/2017, 9:46 AMconst config = {
mutation,
variables,
optimisticUpdater: proxyStore => {
// 1 - create the `newNote` as a mock that can be added to the store
const id = 'client:newNote:' + tempID++;
const newNote = proxyStore.create(id, 'Note');
console.log(newNote);
console.log(variables);
newNote.setValue(id, 'id');
console.log(variables);
Object.keys(variables.input).forEach(key =>
newNote.setValue(variables.input[key], `${key}`)
);
// // 2 - add `newNote` to the store
const viewerProxy = proxyStore.get(viewerId);
console.log(viewerProxy);
const connection = ConnectionHandler.getConnection(
viewerProxy,
'ListPage_allNotes'
);
if (connection) {
ConnectionHandler.insertEdgeAfter(connection, newNote);
}
},
updater: proxyStore => {
// 1 - retrieve the `newNote` from the server response
const createNoteField = proxyStore.getRootField('createNote');
const newNote = createNoteField.getLinkedRecord('Note');
// 2 - add `newNote` to the store
const viewerProxy = proxyStore.get(viewerId);
const connection = ConnectionHandler.getConnection(
viewerProxy,
'ListPage_allNotes'
);
if (connection) {
ConnectionHandler.insertEdgeAfter(connection, newNote);
}
},
onError: error => console.log(error)
};
commitMutation(environment, config);
}
Thank you.