-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Determine whether the query was triggered by an invalidation #4757
Comments
Interesting! May I know the usecase for which you need this? |
Thanks for the response. Our project has a primary and replica database. We try to make queries to our replica database but there is some lag before the data is updated there, so we query from the primary db immediately after a mutation. Basically I want to conditionally query from the primary db if the query refetch was triggered by an invalidation. I imagine this is a reasonably common scenario. I have a workaround, which is to automatically log any invalidations and their time in a redux state object, so I can check for invalidations within the last x seconds when querying. As far as I can tell, there is no way to access that data by default, but let me know if I'm wrong. Also, there isn't anything useful in the documentation about |
@kelly-hansen I think |
@markerikson I'm definitely not using |
Looks like the internal logic relies on this check: function isForcedQuery(
arg: QueryThunkArg,
state: RootState<any, string, ReducerPath>,
) {
const requestState = state[reducerPath]?.queries?.[arg.queryCacheKey]
const baseFetchOnMountOrArgChange =
state[reducerPath]?.config.refetchOnMountOrArgChange
const fulfilledVal = requestState?.fulfilledTimeStamp
const refetchVal =
arg.forceRefetch ?? (arg.subscribe && baseFetchOnMountOrArgChange)
if (refetchVal) {
// Return if it's true or compare the dates because it must be a number
return (
refetchVal === true ||
(Number(new Date()) - Number(fulfilledVal)) / 1000 >= refetchVal
)
}
return false
} I'll be honest, I don't actually know the reasoning behind this code :) |
I'd like to access something like
isInvalidated
from within a queryFn so I can do conditional logic within that queryFn. The only thing I see available isforced
within theapi
object, but that is not alwaystrue
for invalidation refetches. Can this be added?The text was updated successfully, but these errors were encountered: