rametta / rapini

:leafy_green: OpenAPI to React Query (or SWR) & Axios
Apache License 2.0
152 stars 18 forks source link

React Query v4 plans? #9

Closed oscar-nuanxed closed 2 years ago

oscar-nuanxed commented 2 years ago

Hi @rametta !

We just started to use rapini which seems to be a real nice fit in our stack. The installation/setup experience was pretty much plugnplay. Do you have any plans bumping up to react-query v4? Noticed some fork with that but have not investigated myself if there is more to it than these small changes: https://github.com/tawandachiteshe/rapini/commits/main

Or any other plans for the project would ofc also be interesting to hear.

Thanks for sharing your work!

Br, Oscar

rametta commented 2 years ago

Hello @oscar-nuanxed, yes there are plans to support react query v4. I would like to do it in a backwards compatible way. So I would like to add a new CLI flag, such as --react-query-v4 so users can decide if they want to use react query v3 or v4 in the generated code.

It shouldn't require too much work, just need to find time to get to it. I'm also accepting PR's if anyone wants to give it a shot, I'd be more than happy to review and provide feedback on the PR - which may be faster than waiting for me to do it in the next couple weeks.

oscar-nuanxed commented 2 years ago

Thanks for quick reply @rametta! A CLI flag sounds like a plan. Maybe make it more generic too, assuming there might come a v5 or a partly breaking 4.something? -rqv, --react-query-version 4

We might take a stab at it. Will def make a PR in that case

yuleicul commented 2 years ago

Hi @rametta @oscar-nuanxed, I'm trying to implement the feature. Firstly to find the differences between generated files respectively using React Query v3 and v4, I used React Query codemod to transform the v3 generated file to v4 version. The result is that there is only one difference:

- import { useQuery, useMutation, useQueryClient, type QueryClient, type UseMutationOptions, type UseQueryOptions, type MutationFunction, type UseMutationResult, type UseQueryResult } from "react-query";
+ import { useQuery, useMutation, useQueryClient, type QueryClient, type UseMutationOptions, type UseQueryOptions, type MutationFunction, type UseMutationResult, type UseQueryResult } from "@tanstack/react-query";

So I'm thinking that if it's necessary to support react query v4. If it is, I'm thinking what the best way is.

yuleicul commented 2 years ago

Hi @rametta , I'm also thinking that wouldn't it be cool if we can support different query libraries, such as SWR. I'm very interested to implement that part.

rametta commented 2 years ago

Hey @yuleicul @oscar-nuanxed , I've added support for react query v4 in this pr https://github.com/rametta/rapini/pull/10 it should be deployed to npm very shortly and ready to use.

@yuleicul In regards to supporting SWR, is that something you need? I'm not opposed to the idea

rametta commented 2 years ago

V4 support is now in rapini@1.10.0 and can be used by adding the CLI flag called -rq-v4

yuleicul commented 2 years ago

Hi @rametta, after checking out your code I learned a lot, and the idea to support SWR occurred. In my opinion, implementing the support to SWR can help me understand your code better. I think it's a good opportunity for me to learn more about TypeScript Compiler API. If you are not opposed to that, I'm going to do it in the next couple of weeks.

oscar-nuanxed commented 2 years ago

Nice! thanks @rametta , switched to v4 and it looks to be working as expected :+1: