How to refetch active Apollo queries in PWA Studio on user action #3159
Jordaneisenburger
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In some use cases you need to refetch your GraphQL queries on a user action. To do this you need to tell your
<query>
component to refetch the data. Triggering this can be hard to do from a different part of your code base.As an example:
I have a B2B webshop. The customer is on the product page and can see regular/general prices. But when he logs in the product info/prices need to update to reflect his special info/prices.
There is no easy way to do this besides either doing a page reload that will force reload the whole page and queries or use Apollo's
client.resetStore()
but this will reset the whole store and refetch all active queries.To do this more surgical we can use something like this snippet.
Implementation
Beta Was this translation helpful? Give feedback.
All reactions