question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

client.resetStore() does not refetch in-flight queries

See original GitHub issue

Thank you for the great product! I love how easy Apollo Client makes it to bind remote state into my React application.

I’m having a small issue with how client.resetStore() functions with regards to in-flight queries:

Intended outcome: When client.resetStore() is called, it should be assumed that the application state has fundamentally changed in a way that makes the results of all previous queries stale. The documentation suggests that this is the case:

The easiest way to ensure that the UI and store state reflects the current user’s permissions is to call client.resetStore()

Actual outcome: client.resetStore() refetches returned queries, but not currently in-flight queries.

This means that it doesn’t work as a means to clear out stale application state after the state of the application has fundamentally changed (i.e. after login or logout).

Furthermore, this presents a risk of “leaking” information after logout via the Apollo cache. For example:

logout();
// Clear the Apollo cache to clear any cached sensitive information
await client.resetStore();

If a getSensitiveInformation query were in-flight at this time using authorization available at query-time but unavailable after logout, then the user will continue to see that state even after logout.

How to reproduce the issue: I’ve created a code sandbox to reproduce the issue here. In that code sandbox, there’s also a link to a Loom video where the issue is reproduced.

Suggested fix: client.resetStore() should clear the cache for returned queries and in-flight queries. Maybe the results of any in-flight queries should be ignored, also? (i.e. they shouldn’t transition their corresponding useQuery loading status until the query launched by client.resetStore() has returned). I’m less sure on the correct behavior here.

Versions

❯ npx envinfo@latest --preset apollo
npx: installed 1 in 1.486s

  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 12.13.0 - ~/.asdf/installs/nodejs/12.13.0/bin/node
    Yarn: 1.22.4 - ~/.asdf/installs/nodejs/12.13.0/.npm/bin/yarn
    npm: 6.12.0 - ~/.asdf/installs/nodejs/12.13.0/bin/npm
  Browsers:
    Chrome: 87.0.4280.141
    Safari: 14.0.1
  npmPackages:
    @apollo/client: 3.3.6 => 3.3.6

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
zeptonautcommented, Mar 18, 2021

Would still love to see this get resolved 👍

1reaction
unutoiulcommented, Jan 18, 2021

No,

I’m asking about reactive variables as state management:

https://www.apollographql.com/docs/react/local-state/reactive-variables/

Read more comments on GitHub >

github_iconTop Results From Across the Web

clearStore() vs resetStore() - Help - Apollo GraphQL
resetStore() after your login or logout process has completed. This will cause the store to be cleared and all active queries to be...
Read more >
ApolloClient - Client (React) - Apollo GraphQL Docs
Remove all data from the store. Unlike resetStore , clearStore will not refetch any active queries. onClearStore(cb): () => any.
Read more >
apollo's useQuery data does not update after client.resetStore()
It is because I am removing the localStorage authToken and then the client.resetStore() is doing all queries and erroing becausing it's not ......
Read more >
https://unpkg.com/apollo-client@2.0.0-alpha.4/src/...
It is used to send GraphQL documents (i.e. queries * and mutations) to a ... resetStore.bind(this); // Attach the client instance to window...
Read more >
graphql_flutter 5.0.0-nullsafety.1 | Flutter Package - Pub.dev
It also adds an experimental client.resetStore({refetchQueries = true}) for refetching the results of all observed queries (not mutations), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found