Created
September 10, 2018 06:55
-
-
Save azirbel/c78f317e2e217e1782f639b97e066610 to your computer and use it in GitHub Desktop.
Example Apollo higher-order component for mutations
This file contains 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
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