Closed ElisePatrikainen closed 1 month ago
I think it's better for this to just be automatic. The refresh of the data should only fetch if the query is active. If it's not being used, it will be invalidated but not fetched until it's needed somewhere
I hadn't thought about that, that's smart! Doing this first seems by far to be the best solution indeed - and we can still see later if people need to have more control on it (for example to save the refresh call after an optimistic update).
Currently, query invalidation is done through the
keys
mutation does not allow to choose if the query should be refetch immediately or not (and therefore refetches immediately). It would be nice to also expose this possibility, I see two use cases for that :['item', id]
mutation : after a mutation, one might want to invalidate the['item', id]
query, which is needed on the current page, but also maybe the[items]
query, which is not needed on the current page but might be needed later. In that case, it would be better to just invalidate the[items]
query without triggering its refetch, since we don't need it right now.One option for allowing this could be to let passing a
refetch
option in thekeys
mutation option: for examplekeys: [{ key: [www, xxx], refetch: false }, [yyy, zzz]
(with keeping the possibility to pass only the key, instead of the object, where then the refetch option would be set to true).