Proxy prisma calls to FE with tRPC

Hi there. First of all, I'd like to thank everyone involved in the T3 project. It is really awesome. I have a question. Is there a way to just proxy prisma calls to FE with tRPC? So that we don't have to create procedures, duplicate inputs... Just something like:
export const appRouter = router({
prisma,
custom: customProcedures
});
export const appRouter = router({
prisma,
custom: customProcedures
});
And then on the FE:
const post = trpc.prisma.post.findUnique(variables)
const post = trpc.prisma.post.findUnique(variables)
if all you need is something simple. And
const smthSpecific = trpc.custom.post.doSmthSpecific(variables)
const smthSpecific = trpc.custom.post.doSmthSpecific(variables)
when you need to do something with, let's say, permissions check or some other custom logic that prisma is not aware of. That would be so cool, because, ATM, most of my procedures is boilerplate, where I create them just to make existing prisma endpoints available at FE with exactly the same API, for example:
export const postRouter = router({
findUnique: publicProcedure
.input(z.object({ id: z.number() }))
.query(({ input, ctx }) => {
return ctx.prisma.post.findUnique({
where: { id: input.id },
})
}),
findMany: publicProcedure.query(({ ctx }) => {
return ctx.prisma.post.findMany()
}),
})
export const postRouter = router({
findUnique: publicProcedure
.input(z.object({ id: z.number() }))
.query(({ input, ctx }) => {
return ctx.prisma.post.findUnique({
where: { id: input.id },
})
}),
findMany: publicProcedure.query(({ ctx }) => {
return ctx.prisma.post.findMany()
}),
})
9 Replies
Neto
Neto3y ago
at that point, why even use trpc?
yantakus
yantakusOP3y ago
@Neto You mean using react server components, so you just hit prisma from FE directly? Because with this approach, as I understand, every call to DB is always done from the server, not from the client, so we don't need any http API layer.
Neto
Neto3y ago
You don't need exactly yo use server components with react to use prisma
Neto
Neto3y ago
Vercel Documentation
How to Build a Fullstack App with Next.js, Prisma, and PostgreSQL
Create a fullstack application with Next.js, Prisma, PostgreSQL, and deploy to Vercel.
yantakus
yantakusOP3y ago
But then you have to use @prisma/client and then there are compiled types, codegen, etc. all the stuff that we are so glad to get rid off with tRPC.
Neto
Neto3y ago
As a example
yantakus
yantakusOP3y ago
So the question is - do we need tRPC at all with next.js 13 and server components? Am I missing something? @theo would be great to have your input on this topic. Thanks.
Neto
Neto3y ago
Don't @ him But iirc t3 will have to do something with it But for rn, isn't even stable to real usage Even then, typesafe calls still will be amazing to have
theo (t3.gg)
theo (t3.gg)3y ago
Timeout for @ing me, especially since I have 2 fucking videos on this Also re: this request, no. tRPC proxies procedures, not arbitrary objects. Don't proxy all of Prisma to client. That is a disaster.

Did you find this page helpful?