trpc - Calling a route inside itself

Based on the documentation here, you can call another route on the server side using:
const caller = route.createCaller({})
const caller = route.createCaller({})

However, if the route is within itself, is it possible to do so using the this keyword? If not, how can one call a route sibling?
import { z } from "zod";

import { router, publicProcedure } from "../trpc";

export const appRouter = router({
example: exampleRouter,
});

export const exampleRouter = router({
hello: publicProcedure.query(() => "Hello"),
world: publicProcedure.query(() => "World"),
greet: publicProcedure.query(function () {
const caller = this.createCaller({});
// const caller = appRouter.createCaller({}) ????
return caller.hello() + caller.world();
}),
});
import { z } from "zod";

import { router, publicProcedure } from "../trpc";

export const appRouter = router({
example: exampleRouter,
});

export const exampleRouter = router({
hello: publicProcedure.query(() => "Hello"),
world: publicProcedure.query(() => "World"),
greet: publicProcedure.query(function () {
const caller = this.createCaller({});
// const caller = appRouter.createCaller({}) ????
return caller.hello() + caller.world();
}),
});
2 Replies
Paul
PaulOP2y ago
Thanks!
Want results from more Discord servers?
Add your server