Call route within route in server
How can I call a route in a different route. For example I have this route:
I want to call that create function in a different route like this:
But that does not work, any ideas?
3 Replies
https://trpc.io/docs/server/server-side-calls
https://www.youtube.com/watch?v=G2ZzmgShHgQ&t=1s&pp=ygUNYWR2YW5jZWQgdHJwYw%3D%3D
Server Side Calls | tRPC
You may need to call your procedure(s) directly from the same server they're hosted in, router.createCaller() can be used to achieve this.
Christopher Ehrlich
YouTube
Advanced tRPC - Callers, functions, and gSSP
🚨 createSSGHelpers has been renamed to createServerSideHelpers 🚨
Repo for this video: https://github.com/c-ehrlich/you-dont-need-callers
If you want to use schema in the frontend, they cannot be imported from the same file as things that run specifically in the backend. One solution would be to put them into a
procedureName.schema.ts
or simi...tdlr you probably dont want to call your own backend from your backend
extract the shared logic into a single external function you call from both places
TRPC specifically recommends against calling other routes within routes even using the server side stuff