Closed
Description
When we pass the queryKey
to the QueryFunctionContext
, we make sure that it is an Array. This is great for global query functions, because you can just work with an Array<unknown>
on type level.
However, in other situations where we provide the whole Query
, accessing query.queryKey
will still be string|Array<unknown>
. For example, when using the predicate
filter:
queryClient.invalidateQueries({
predicate: (query) => query.queryKey...
})
here, it is not guaranteed that query.queryKey
is an Array, so it's harder to work with
Proposed solution
only allow Arrays
for QueryKeys
(and for MutationKeys
as well)
a codemod would be very good for this. we could let it run over all our examples, and we'd also need to update everything in the docs.
things to take care about:
- useQuery
- useInfiniteQuery
- useMutation
- queryCache.find
- mutationCache.find
- all methods on queryClient