vpjmV
tRPC11mo ago
5 replies
vpjm

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)
    })


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;}>>


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!
Was this page helpful?