Created
August 25, 2017 15:36
-
-
Save gc-codesnippets/624069731ec7900cc998df8441df2b21 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
| optimisticUpdater: (proxyStore) => { | |
| // 1 - create the `newPost` as a mock that can be added to the store | |
| const id = 'client:newPost:' + tempID++ | |
| const newPost = proxyStore.create(id, 'Post') | |
| newPost.setValue(id, 'id') | |
| newPost.setValue(description, 'description') | |
| newPost.setValue(imageUrl, 'imageUrl') | |
| // 2 - add `newPost` to the store | |
| const viewerProxy = proxyStore.get(viewerId) | |
| const connection = ConnectionHandler.getConnection(viewerProxy, 'ListPage_allPosts') | |
| if (connection) { | |
| ConnectionHandler.insertEdgeAfter(connection, newPost) | |
| } | |
| }, | |
| updater: (proxyStore) => { | |
| // 1 - retrieve the `newPost` from the server response | |
| const createPostField = proxyStore.getRootField('createPost') | |
| const newPost = createPostField.getLinkedRecord('post') | |
| // 2 - add `newPost` to the store | |
| const viewerProxy = proxyStore.get(viewerId) | |
| const connection = ConnectionHandler.getConnection(viewerProxy, 'ListPage_allPosts') | |
| if (connection) { | |
| ConnectionHandler.insertEdgeAfter(connection, newPost) | |
| } | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment