vpjm
vpjmโ€ข2w ago

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!
3 Replies
vpjm
vpjmOPโ€ข2w ago
I saw that there are several Git issues related to this topic, so feel free to reply to this post ! :trpc:
Alex / KATT ๐Ÿฑ
GitHub
Dynamically type the data result of a hook according to inputs ยท tr...
Hey, folks! We ran into a hiccup with trying to dynamically type the data that comes back from our endpoint. Imagine an identity endpoint that can return either a string or a number: // I recognize...
vpjm
vpjmOPโ€ข2w ago
Thank you very much, I am now sure that it's not doable right now ๐Ÿค Have an excellent day! (PS: I will close the post at the end of the day if anyone wants to add something in the meantime)

Did you find this page helpful?