prisma-trpc-generator icon indicating copy to clipboard operation
prisma-trpc-generator copied to clipboard

Support Include and Select

Open omar-dulaimi opened this issue 2 years ago • 1 comments

Discussed in https://github.com/omar-dulaimi/prisma-trpc-generator/discussions/11

This requires work to be done here in this library and also in Prisma Zod Generator.

omar-dulaimi avatar Jul 15 '22 16:07 omar-dulaimi

Here's a similar package for graphql based on prisma, which you can use as an inspiration: https://github.com/MichalLytek/typegraphql-prisma

konuch avatar Aug 27 '22 08:08 konuch

Any update on this?

Kliton avatar Oct 14 '22 09:10 Kliton

Any update on this?

Not much time these days unfortunately. Though PRs are welcomed if anybody decided to work on it.

omar-dulaimi avatar Oct 14 '22 09:10 omar-dulaimi

One of the engineers on my team is going to take a crack at this. Assuming success, a PR will be forthcoming!

kristinlindquist avatar Oct 19 '22 13:10 kristinlindquist

Select is live with the latest release 0.5.0. Special thanks to @BitPhoenix

omar-dulaimi avatar Nov 04 '22 15:11 omar-dulaimi

🙏

vikt0r0 avatar Jan 14 '23 13:01 vikt0r0

I am able to generate the schemas by specifying to the generator to make include and select queries, and I can issue the query, e.g.:

const jobsQuery = trpc.project.job.findManyJob.useQuery({
  take: 40,
  include: { employer: true },
});

I can see that the proper database queries are made to retrieve the correct data from the DB, but how do I access the included data? I can only access the ID, despite my relationships being defined (i.e. they work in prisma studio):

{jobsQuery.data?.map((job) => {
  <p>{job.employerId}</p>;
})}

Also, previously job had type Job of the model generated from the Prisma schema. Now it is just SerializeObject<UndefinedToOptional<Job>>. What am I doing wrong?

vikt0r0 avatar Jan 20 '23 22:01 vikt0r0

@omar-dulaimi I'm dealing with the same issue that @vikt0r0 mentioned above - when using include, the type produced by the query doesn't include the linked relations. I'd like to take a stab at a PR, but I'm not really sure where to start. If you could point me in the right direction, hopefully I can figure something out.

Thanks for this package by the way!

zrachlin avatar Feb 01 '23 02:02 zrachlin

Hey @vikt0r0 @zrachlin Please open a new issue with reproducible steps so I can take a look at it. I would appreciate it if you shared a sample schema and prisma version, etc.

omar-dulaimi avatar Feb 03 '23 11:02 omar-dulaimi

Sure. I also have a project I can send you if you want me to.

vikt0r0 avatar Feb 04 '23 22:02 vikt0r0