#Handling queries when fetch function parameter change but you want the cache to remain

1 messages · Page 1 of 1 (latest)

hybrid willow
#

Hey guys,

My use case goes like this, I'm using react-query to build a package for managing flags (could be feature flags or flags for ab-testing).
This package is used as a shared dependency in micro-frontend environment (meaning multiple applications are basically using the same query cache).

This works really nice and everything is in sync.

Sometimes different app will look at the same flag but with different options that needs to be sent to the server. If I include this options as part of the queryKey, it will basically treat it as 2 separate cache instances (which is good for most cases but not for me for this one).
How would you advise doing this?

Removing the options from the queryKey and manually sending them to the queryFn?
And also, sometimes I need to refetch with different options (but still using the same cache). I see that refetch doesn't support this at the moment.

Thanks in advance

grave merlin
#

Does the api return the same data regardless of the options that are provided? If so, how are the options used?

hybrid willow
#

Hey Julien

#

Yes, the API basically returns the same data, the options are for letting the server know if the user actually made an impression regarding this flag (This is how the API works, not something which is under my control. You basically can retrieve data on a flag, and you can also call the same api with different options which means that you don't only want the flag data but also want an analytic impression to be made)

raw bone
#

Hi 👋

Refetch will never support this. Refetch does what the name suggests (refetches a query). If you're changing the query, it's a different query.

If you could explain why it making a new query is undesirable then I can probably suggest an approach 🙂