Is it possible to call one procedure in another?
I have multiple routers in my trpc server. For example userRouter (e.g. procedure: getUser) and postRouter (e.g. procedure: updatePost).
Is it possible to call the getUser procedure from my userRouter in my updatePost procedure? Or are all procedure effectively independent.
5 Replies
it is, but it's better to make shared functions
if you need to though you can see https://trpc.io/docs/server-side-calls
Server Side Calls | tRPC
You may need to call your procedure(s) directly from the server, createCaller() function returns you an instance of RouterCaller able to execute queries and mutations.
Oh thanks, so we can use createCaller within other procedures?
theoretically yes
but be careful of circular deps
oof I got hit with circular deps today in a something tRPC-like, interesting which cases you can get away with it in and which you can't