Instantly share code, notes, and snippets.

Embed
What would you like to do?
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