Skip to content

Instantly share code, notes, and snippets.

@azirbel
Created September 10, 2018 06:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azirbel/c78f317e2e217e1782f639b97e066610 to your computer and use it in GitHub Desktop.
Save azirbel/c78f317e2e217e1782f639b97e066610 to your computer and use it in GitHub Desktop.
Example Apollo higher-order component for mutations
import { graphql } from 'react-apollo'
import { UPDATE_WORD_MUTATION } from '<GraphQL query strings file>'
export const withUpdateWord = cc =>
graphql(UPDATE_WORD_MUTATION, {
props: ({ mutate }) => ({
updateWord: ({ id, newData, optimisticNewModel }) => {
return mutate({
variables: {
id,
...newData,
},
context: {
debounceKey: `updateWord:${id}`,
},
optimisticResponse: {
__typename: 'Mutation',
word: {
__typename: 'Word',
...optimisticNewModel,
},
},
})
},
}),
withRef: true,
})(cc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment