vpjm
vpjm3d ago

Calling endpoint within another endpoint

Hi, I need to get the result of one of my endpoints, but I can't just call the underlying function directly — because every endpoint is wrapped with security and middleware before being exposed through the tRPC appRouter. So instead of bypassing those layers, I need to trigger the full chain — essentially making a proper call to the endpoint itself (as if it were external), even from inside another tRPC procedure. What's the recommended way to do this?
1 Reply
vpjm
vpjmOP3d ago
Can I call tRPC procedure inside another procedure? - Theo's Typesa...
Something like this:
export const mainRouter = createTRPCRouter({
create: privateProcedure
.mutation(async ({ ctx }) => {
...
doSomething({someInput: ""}) // call doSomething here with inputs
}),
doSomething: privateProcedure
.input(
z.object({
someInput: z.string(),
})
)
}
export const mainRouter = createTRPCRouter({
create: privateProcedure
.mutation(async ({ ctx }) => {
...
doSomething({someInput: ""}) // call doSomething here with inputs
}),
doSomething: privateProcedure
.input(
z.object({
someInput: z.string(),
})
)
}

Did you find this page helpful?