Created
August 25, 2017 15:35
-
-
Save gc-codesnippets/c5a99343a75706f8bc5964f602b68573 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
| // 1 | |
| import { | |
| commitMutation, | |
| graphql, | |
| } from 'react-relay' | |
| import {ConnectionHandler} from 'relay-runtime' | |
| import environment from './Environment' | |
| // 2 | |
| const mutation = graphql` | |
| mutation CreatePostMutation($input: CreatePostInput!) { | |
| createPost(input: $input) { | |
| post { | |
| id | |
| description | |
| imageUrl | |
| } | |
| } | |
| } | |
| ` | |
| // 3 | |
| export default (description, imageUrl, viewerId, callback) => { | |
| // 4 | |
| const variables = { | |
| input: { | |
| description, | |
| imageUrl, | |
| clientMutationId: "" | |
| }, | |
| } | |
| // 5 | |
| commitMutation( | |
| environment, | |
| { | |
| mutation, | |
| variables, | |
| // 6 | |
| optimisticUpdater: (proxyStore) => { | |
| // ... you'll implement this in a bit | |
| }, | |
| updater: (proxyStore) => { | |
| // ... this as well | |
| }, | |
| // 7 | |
| onCompleted: () => { | |
| callback() | |
| }, | |
| onError: err => console.error(err), | |
| }, | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment