check if query
or mutation
is happening
#120
-
I want to retrieve if any query is fetching and if any mutation is mutating. Is there a way to do this? I'm currently using this: https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientisfetching ps: if there isn't a way - and it would be a welcome feature - I could implement something using this as reference. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
This can be done by checking the query cache. I’m interested in knowing the use case as that would change how and if this needs to be exposed |
Beta Was this translation helpful? Give feedback.
-
For me it's just a easy way to put a global check. I have a modal component that does multiple different mutations but each one of them has a different mutationKey since I'm using this pattern automatic revalidation so It's easy to just check if there's any mutation happening. I think the key role would be supporting the filters. I think it's less relevant having an |
Beta Was this translation helpful? Give feedback.
-
FYI filters are supported. The For queries, you can do const isLoading = computed(() => queryCache.getEntries({ predicate: (entry) => entry.asyncStatus.value === 'loading' })) For mutations, this is not yet possible until the mutation store (#17) is exposed. Once exposed, they will have similar methods. When it comes to invalidations, check the docs guide on this. On the future it would be possible to pass a global If the purpose of these APIs are global, they are likely to be used one or two times in an app, so they will probably not be a dedicated API for it to promote using methods like |
Beta Was this translation helpful? Give feedback.
FYI filters are supported. The
queryCache
is still not properly documented, so only the API is there. Relying on autocompletion helps but eventually the docs will be there.For queries, you can do
For mutations, this is not yet possible until the mutation store (#17) is exposed. Once exposed, they will have similar methods.
When it comes to invalidations, check the docs guide on this. On the future it would be possible to pass a global
onSettled
option for mutations to invalidate everything (although I would highly advise against it).If the purpose of these APIs are gl…