Apollo-client: useQuery returns undefined data after clearStore()

Created on 25 Jul 2020  路  1Comment  路  Source: apollographql/apollo-client

Intended outcome:
I'm fetching a query like this:

let headers;

if (logged) {
  headers = {
    authorization: `Bearer test`
  };
}

const { data } = useQuery(QUERY, {
  context: {
    headers
  }
});

I was hoping that when I changed the headers of the request a refetch would happen, but I'm getting the previous cached response instead.

So I thought that by doing client.clearStore() before changing the logged flag would result in the cache being cleared and a fresh network request to be sent.

Actual outcome:
A new network request is being sent and completed successfully, however the data property of the response comes with the value undefined.

How to reproduce the issue:
Sandbox

Most helpful comment

Possibly a dupe of #6044 and discussed here https://github.com/apollographql/apollo-client/issues/6359? My approach to this was creating a whole new client upon these sorts of logged in / logged out state changes. So not sure what is the use of clearStore().

>All comments

Possibly a dupe of #6044 and discussed here https://github.com/apollographql/apollo-client/issues/6359? My approach to this was creating a whole new client upon these sorts of logged in / logged out state changes. So not sure what is the use of clearStore().

Was this page helpful?
0 / 5 - 0 ratings