Feature Request: expose queryOptions of react-query v5
dohomi opened this issue · 1 comments
Is your feature request related to a problem? Please describe.
It would be a great addition to react-query if the queryOptions
would be used and exposed by the generator
Describe the solution you'd like
Based on https://tanstack.com/query/latest/docs/react/guides/query-options a great way to compose queries is to use the queryOption
. It would be ideal if this would be exposed at the generator level.
Additional context
A very nice write down from one of the maintainer about queryOptions
is available here https://tkdodo.eu/blog/the-query-options-api
I did a deeper look into this because with the new loader functionalities on Tanstack Router, React Router or NextJS I could archive similar behaviour with a little bit more code:
{
exposeQueryKeys: true,
exposeFetcher: true,
addSuspenseQuery: true,
}
// in route config
loader: ({userId}) => queryClient.ensureQueryData({
queryKey: useUserQuery.getKey({ id: userId }),
queryFn: useUserQuery.fetcher({ id: userId })
})
// in my components
useSuspenseUserQuery({id: userId})
This is already great, it would be great if addSuspenseQuery
is not documented because that flag was missing inside the docs.
I think this plugin could greatly improve when queryOptions
would be introduced into the codegen and both queries, suspense queries and all other options would make use of the generated query options for each query (and mutation)