Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to readQuery() and writeQuery() from Vue-Apollo Store?

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.

like image 404
Zezi Reeds Avatar asked Nov 24 '18 18:11

Zezi Reeds


People also ask

How do I clear the Apollo Client cache?

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.

How do you update Apollo cache after query?

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.

How does Apollo store cache?

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.

How do I use Apollo Client developer tools?

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.


1 Answers

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,
        },
      })
    },
like image 156
calmar Avatar answered Nov 15 '22 07:11

calmar