Search code examples
vue-apollo

How to get remote GraphQL data when i use local state in Vue-apollo


I used Vuex with vue-apollo.

But now i know vue-apollo store data in cache then i can use local state by using cache.

When i saw offical document from local state

I knew how can i get and set data from local state but there is no mention how to get data from remote server.

I saw this code from document, they just write to cache temp data.

cache.writeData({
  data: {
    todoItems: [
      {
        __typename: 'Item',
        id: 'dqdBHJGgjgjg',
        text: 'test',
        done: true,
      },
    ],
  },
});

So, i think i can get remote data by using vue-apollo query like below.

apollo: {
  world: {
    query: gql`query {
      hello
    }`,
    update: data => data.hello
  }
}

After i get server data like above, i can query/mutate from local state.

But this is only my guess, is this correct?


Solution

  • I found example from github. My guess is right.