I want to edit some data in the cache manually.
How can I readQuery()
and writeQuery()
in vue-apollo directly from a method of a Vue component? Im looking for something like this.$apollo.readQuery(...)
, which does not work. Where do I get the store
instance from?
I mean the store instance from update()
method in e.g. this.$apollo.mutate
.
Resetting the cache Sometimes, you might want to reset the cache entirely, such as when a user logs out. To accomplish this, call client. resetStore . This method is asynchronous, because it also refetches any of your active queries.
For the automatic update to work your user needs to be recognised by the cache. You can do that by either adding an id field and selecting it in both the query and the mutation or implementing a dataIdFromObject function in Apollo Client 2.
Apollo Client stores the results of your GraphQL queries in a local, normalized, in-memory cache. This enables Apollo Client to respond almost immediately to queries for already-cached data, without even sending a network request.
While your app is in dev mode, the Apollo Client Devtools will appear as an "Apollo" tab in your web browser inspector. To enable the devtools in your app in production, pass connectToDevTools: true to the ApolloClient constructor in your app.
Inside a component you can grab the methods from this.$apollo.provider.defaultClient
methods: {
async doQuery (my_data) {
const apolloClient = this.$apollo.provider.defaultClient
apolloClient.writeQuery({
query: QUERY,
data: {
data: my_data,
},
})
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With