Skip to content

Instantly share code, notes, and snippets.

@gc-codesnippets
Created August 25, 2017 15:35
Show Gist options
  • Select an option

  • Save gc-codesnippets/c5a99343a75706f8bc5964f602b68573 to your computer and use it in GitHub Desktop.

Select an option

Save gc-codesnippets/c5a99343a75706f8bc5964f602b68573 to your computer and use it in GitHub Desktop.
// 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