Skip to content

Instantly share code, notes, and snippets.

@smolinari
Created April 5, 2020 14:41
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 smolinari/34ed42fe3b4a8f6a47766bc0a6fd7396 to your computer and use it in GitHub Desktop.
Save smolinari/34ed42fe3b4a8f6a47766bc0a6fd7396 to your computer and use it in GitHub Desktop.
<template>
<ApolloMutation
:mutation="mutation"
:update="updateCache"
>
<template v-slot="{ mutate, loading, error }">
<q-checkbox
v-model="todoToggle"
@input="mutate"
/>
<p v-if="error">There has been an error<br>{{error}}</p>
</template>
</ApolloMutation>
</template>
<script>
import { queries, mutations } from 'src/graphql/Todos'
....
data () {
return {
todoToggle: this.completed,
mutation: mutations.toggleTodo
}
},
methods: {
updateCache (store, { data: { toggleTodo } }) {
const data = store.readQuery({ query: queries.getTodos })
data.todos.find((todo) => {
if (todo.id === this.id) {
todo.completed = !todo.completed
}
})
store.writeQuery({ query: queries.getTodos, data })
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment