Can I call tRPC procedure inside another procedure?

AApestein5/31/2023
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
Wwhatplan5/31/2023
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.
Wwhatplan5/31/2023
what you probably want to do is extract the shared logic to a function you can call from both procedures
Wwhatplan5/31/2023
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...

Looking for more? Join the community!