Skip to content
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

Redux Toolkit/RTK Query support? #393

Open
t1mmen opened this issue Sep 23, 2023 · 5 comments
Open

Redux Toolkit/RTK Query support? #393

t1mmen opened this issue Sep 23, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@t1mmen
Copy link

t1mmen commented Sep 23, 2023

This is mostly a question, as I'm not 100% sure it's reasonable to even try.

Situation

I'm building an API on ts-rest with one use-case being a NextJS app using react-query. This experience is absolutely amazing, and I am wildly in love with gains in productivity, safety, and documentation. Fantastic work! 👏

Upcoming challenge

The ts-rest API will be consumed by a pre-existing app that uses Redux Toolkit with RTK Query.

The excellent types coming out of ts-rest will certainly ease this implementation, but given that ts-rest has spoiled me rotten for DX and productivity gains, I'm keen to bring all of that into the Redux-based app.

I don't yet have hands-on experience with RTK Query, but I think I'm looking for a way to leverage ts-rest contracts via RTK's createApi() to avoid repetition, likely with a wrapper around the fetchBaseQuery().

PS: We at @Timely just became sponsors. I'm not opposed to a offering a bounty on this too, btw.

@damieng57
Copy link
Contributor

+1 for this feature, it will be great to have an integration with RTK Query. And a good point to adopt ts-rest instead of tRPC.

@spgandhi
Copy link

I started using ts-rest this week and like many others just feel in love with the DX and how fast and reliably I am able to build things.

And now I am looking for RTK Query integration and stumbled on this. I am going attempt to create a RTK Query wrapper to work with ts-rest. If I get to something working, I'll post my updates here :)

@Gabrola
Copy link
Member

Gabrola commented Apr 15, 2024

@t1mmen Sorry, I've just gotten to this issue, as I've been slowly going through our backlog.

I see huge merit in supporting older libraries like Redux/RTK Query, however, my fear is that it would become abandonware since none of the maintainers currently use it AFAIK. Personally, I've not touched a Redux codebase in 6 years, so even before the birth of RTK Query 😅

However, I've cleaned up and refactored out a lot of the common code between the different ts-rest client libraries, so, although I'm leaning away from it, it should be much easier now to introduce a new library. So maybe, if you have someone from @Timely to assist with the maintenance of that specific package, maybe we could make it work (also thank you for sponsoring, I just noticed ❤)

I would suggest a gradual migration to something like React Query. Although I haven't thoroughly thought this one out, I believe it should be relatively simple to use React Query's QueryObserver to subscribe to queries, and then update your Redux store by using updateQueryData. This should allow you to even gradually replace singular queries without having to replace every single usage of that same query at once.

@Gabrola Gabrola added the enhancement New feature or request label Apr 15, 2024
@t1mmen
Copy link
Author

t1mmen commented Apr 15, 2024

We solved our use-case by generating an OpenAPI spec, then generating RTKQ slices from that same spec. It works quite well, so our immediate needs are covered.

While I'd happily go react-query for a new project, we're too entangled in Redux for our core product at this stage.

https://redux-toolkit.js.org/rtk-query/usage/customizing-create-api seems like the entry point to start building this. We can't commit to pursuing this now, but if we do at some stage, we'll happily contribute back :)

Thanks again for an awesome project, you've saved us so. much. time!

@Gabrola
Copy link
Member

Gabrola commented Apr 16, 2024

@t1mmen oh that's awesome that that's possible. Great to hear! We're a bit consumed now working on v4 of ts-rest, but for sure we'll evaluate this afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants