Can I call tRPC procedure inside another procedure?

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(),
})
)
}
Solution:
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.
Jump to solution
3 Replies
Solution
whatplan
whatplan2y ago
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.
whatplan
whatplan2y ago
what you probably want to do is extract the shared logic to a function you can call from both procedures
whatplan
whatplan2y ago
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...
Want results from more Discord servers?
Add your server