-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
TanStack Query plugin #653
Comments
Hey @sahinkutlu, would generating |
@mrlubos is there any WIP on this? overall I'm having a good time using fetch API with tanstack query but there are some pain points that.. I'm sure you're aware of given that this is on the roadmap 🙂 |
Yep, I did have a look at it, might prioritise it actually. Will |
@mrlubos yes, that would be perfect & remove a lot of boilerplate |
Hi @mrlubos! Yes generated query options would very nice 👍 When do you think it will be released? |
can't wait too. good work guys |
It would be nice to have. I'm thinking about writing my generator, but if it's implemented in your library it would be just awesome! |
@mrlubos Amazing! I'm so excited for this. 😁 |
Very exciting. RQ support gonna sky rocket this package! |
Looking forward to this. |
I hope that other framework versions of TanStack, like Vue, will also be supported. |
@Jannchie most definitely 🙏 |
Looking forward to use this in combination with vue. Is there an ETA? |
@brmdbr Hopefully within 2 weeks, but if you want to test drive it earlier, send me a message on Discord/email/Twitter/LinkedIn and I can walk you through it (in exchange for some feedback 😈) |
Support for React, Solid, Svelte, and Vue done, currently undergoing testing. If anyone wants to try it out early, add this to your configuration file for React plugins: ['@tanstack/react-query'] for Solid plugins: ['@tanstack/solid-query'] for Svelte plugins: ['@tanstack/svelte-query'] for Vue plugins: ['@tanstack/vue-query'] and feel free to open a new issue if you run into any problems! I don't really expect the APIs to change, but it has not been thoroughly tested (except for React), so you never know! |
@mrlubos It would be nice if we could override some of the tanstack query options. I prefer to set some options manually, such as Here is my idea on how to do this with adding the export const serverGetOptions = (
options: Options<ServerGetData>,
tanstackQueryOptions?: Omit<UndefinedInitialDataOptions<any, Error, any, any[]>, "queryFn">,
) => {
return queryOptions({
...tanstackQueryOptions,
queryFn: async ({ queryKey }) => {
const { data } = await serverGet({
...options,
...queryKey[0].params,
throwOnError: true,
});
return data;
},
queryKey: [
{
params: createQueryKeyParams(options),
scope: "serverGet",
},
...(tanstackQueryOptions ? tanstackQueryOptions.queryKey : []),
],
});
}; |
@RobertOstermann that's fair, I will need to improve types to unlock this feature. In the meantime, you can simply spread the response from this function onto useQuery({
... serverGetOptions(),
enabled: false,
}) |
I was able to do that for most of the options, but struggled to get it working with |
@RobertOstermann what kind of query key are you passing? I would expect TypeScript to complain if it doesn't match the expected shape. That might need to be improved, why are you needing to pass your own query key? |
I was trying to pass in a number. Tried adding it as a new element at the end of the query key array, but no luck. I prefer to pass in my own query key so I can easily invalidate several queries, all which share that same query key, when a mutation is complete. I think it not matching the expected shape was the issue. Also, thanks for all your hard work on this! Super useful. useQuery({
... serverGetOptions(),
queryKey: [...serverGetOptions().queryKey, idNumber],
enabled: false,
}) |
@RobertOstermann we should talk about that use case, perhaps separately. Query key design is important. I've also heard from others they need URL base as part of it so they can target by the client which made the request. |
When using |
Thank you for this nice work. Can you confirm that |
@holtgrewe The question is what do you imagine/understand by that? The plugin is a separate output so the way you generate services does not have an impact on it |
Is it known that using |
@mrlubos the result appears to be incompatible as it does not generate the |
@holtgrewe Ah got you. That should be fixed, thanks for pointing it out @SimenB yes, there are no plans to support the old clients at this time |
Aight 👍 |
@RobertOstermann / @mrlubos could you share some information about how key invalidation in mutations are to be used with the standard / builtin and custom overrides? This would be very useful for newbies to TanStack Query like me. Thanks! |
Hey all, added a quick page on this plugin to docs + StackBlitz example to signal this is ready to be used and welcoming feedback! https://heyapi.vercel.app/openapi-ts/tanstack-query.html |
Related #980 |
queryKey / mutationKey logic is not make sense to me at all, I think should allow user to define it instead of auto autogenerate it |
@himself65 can you explain why? I do agree that eventually we could provide API hooks to customise the output further, but want to hear your take on why the current logic doesn't make sense |
for example, there are apis:
queryKey for /keys and keys/{id} should be |
@mrlubos As mentioned before, I'm using the Vue3 flavor of TanStack query. I'm writing my own composeables to isolate the queries outside of components and make them reuseable. I now need my composeables to be reactive, in other words pass
There is particular support for What do you think? |
@holtgrewe I think that's fair, we can improve types for queries to use the TanStack types just like mutations do |
All, v0.53.0 will contain a fix for #987 |
I see @rkorzhoff. Mind opening an issue please? |
Sure! |
Rather, by default, the plugin should follow the recommendations made by TkDodo on his blog. This allows the invalidation of many queries at once:
|
I agree, I would expect a query with a url Also, making the export const serverGetKeysOptions = (options: Options<ServerGetKeysData>) => {
return queryOptions({
// queryFn: async ({ queryKey ) => {
queryFn: async () => {
const { data } = await serverGetKeys({
...options,
...serverGetKeysQueryKey(options)[0],
throwOnError: true,
});
return data;
},
queryKey: serverGetKeysQueryKey(options),
});
}; |
Hi, I also tested the generated results and found another pain point due to current queryKey design. I think it's common to find clients and servers using different baseUrls for the sample resources for performance and security, since the queryKey is hardly depend on baseUrl, it makes us hard to prefetch queries for server-side rendering. Also, the hey-api/client-fetch client construct a Request object internally which will throw an error if the custom fetch function expect urls without hostname. i.e This can be workaround by using a fake baseUrl and replace it via custom fetch function but very awkward. i would appreciate it if this can be taken into consideration. Thanks for maintaining this great project. It's been extremely helpful for us. |
@yue4u do you have a solution in mind for each of the 2 mentioned issues? |
Thanks for your quick reply!
Like other comments I think following TanStack Query' recommendations is a good practice and queryFn should not depend on the queryKey. Or just make the queryKey option more customizable to let users decide themselves.
IMO it would be more helpful to avoid instancing |
@mrlubos Any update on if this is in the works? |
Description
Hey guys! I saw that the tanstack query generation is coming soon which is awesome. We are planning to migrate our project to use openapi-ts with tanstack-query. In order to avoid double work in our side when should we expect this feature to be shipped? Cheers!
The text was updated successfully, but these errors were encountered: