Skip to content

Instantly share code, notes, and snippets.

@gc-codesnippets
Last active March 26, 2018 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gc-codesnippets/2f994ebfe53250f3ed670d20c121f40e to your computer and use it in GitHub Desktop.
Save gc-codesnippets/2f994ebfe53250f3ed670d20c121f40e to your computer and use it in GitHub Desktop.
const publishMutation = (
<Mutation
mutation={PUBLISH_MUTATION}
update={(cache, { data }) => {
const { drafts } = cache.readQuery({ query: DRAFTS_QUERY })
const { feed } = cache.readQuery({ query: FEED_QUERY })
cache.writeQuery({
query: FEED_QUERY,
data: { feed: feed.concat([data.publish]) },
})
cache.writeQuery({
query: DRAFTS_QUERY,
data: {
drafts: drafts.filter(draft => draft.id !== data.publish.id),
},
})
}}
>
{(publish, { data, loading, error }) => {
return (
<a
className="f6 dim br1 ba ph3 pv2 mb2 dib black pointer"
onClick={async () => {
await publish({
variables: { id },
})
this.props.history.replace('/')
}}
>
Publish
</a>
)
}}
</Mutation>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment