vpjm
vpjm
TtRPC
Created by vpjm on 2/10/2025 in #❓-help
Passing generic inside tRPC query
Hi, I hope you're doing well. Server:
findManyUser: publicProcedure.input(UserFindManyArgsSchema).
query(<I extends Prisma.UserFindManyArgs<DefaultArgs>>({ input }: { input: I }) => {
return prisma.user.findMany(input)
})
findManyUser: publicProcedure.input(UserFindManyArgsSchema).
query(<I extends Prisma.UserFindManyArgs<DefaultArgs>>({ input }: { input: I }) => {
return prisma.user.findMany(input)
})
Nextjs front:
const users = trpc.findManyUser.useQuery({include:{image:true} })
//users : UseTRPCQueryResult<PrismaResultForFindMany<DefaultArgs>, TRPCClientErrorLike<{ input: Prisma.UserFindManyArgs<DefaultArgs>; output: PrismaResultForFindMany<DefaultArgs>; transformer: true;errorShape: DefaultErrorShape;}>>
const users = trpc.findManyUser.useQuery({include:{image:true} })
//users : UseTRPCQueryResult<PrismaResultForFindMany<DefaultArgs>, TRPCClientErrorLike<{ input: Prisma.UserFindManyArgs<DefaultArgs>; output: PrismaResultForFindMany<DefaultArgs>; transformer: true;errorShape: DefaultErrorShape;}>>
I would like to pass the type of my Prisma query ({ include: { image: true } }) to findManyUser, so users has the expected type and not the default type provided by Prisma (without generics : DefaultArgs ). Thanks for your help. Have a great day/night!
6 replies