tRPC but just the React Query abstraction?

I'm integrating with an existing Python backend, but I really like the way tRPC procedures are defined and used (with react query in particular). I could make fetch calls from the NextJS backend to the python backend, because the backends are on the same machine, but I would still prefer to have the browser show the direct API call instead of trying to debug in two separate interfaces. Not sure if that makes sense, but I'm happy to elaborate more if there are any questions 🙂
3 Replies
jingleberry
jingleberry•2y ago
Generate an OpenApi client for your python backend. Then have trpc create some procedures that use the generated client to call your python backend (in your typescript code) Unsure if that’s what you’re looking for exactly tho
Fuzbo
Fuzbo•2y ago
Not quite, but I might look into doing that still. I'm okay with the loose safety between the NextJS backend and the Python backend, as I'm using Zod on the NextJS backend still to validate the request inputs and response from the Python backend. The main thing I want is basically to just be able to use TRPC for the react query abstraction so I can just write the one fetch call I want to make to the Python backend, and then automatically have things like trpc.foo.bar.useQuery() and utils.foo.bar.prefetch() available without having to write a bunch of redundant code.
jingleberry
jingleberry•2y ago
Honestly just skip the trpc part. Generate a frontend openAPI client for your python endpoint. Then pass in the generate functions into react query directly. Should automatically have type safety assuming your backend strictly adhered to the defined spec
Want results from more Discord servers?
Add your server