TaylorFay
TaylorFay2y ago

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
Alex / KATT 🐱
it is, but it's better to make shared functions
Alex / KATT 🐱
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.
TaylorFay
TaylorFayOP2y ago
Oh thanks, so we can use createCaller within other procedures?
Alex / KATT 🐱
theoretically yes but be careful of circular deps
ballingt
ballingt2y ago
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