0

I have a react application that utilizes Prisma backend. Prisma backend is in it's own separate library with models generated from the database. The intention is that the entire application can be within one repository with both the front end and backend using typescript. The models that the React application uses are the same models Prisma generated.

In Prisma when I do relations such as the 'Include' statement. I can't seem to access that property in my react application. Is there a way for me to access the full type including that of the 'Include' in my React application?

get full type on prisma client talks about this but my problem is where I define the full type including the relation i.e. 'UsersWithCars'. I don't want to create a new model within my React application because that just means there are two sets of model I have to manage, the Prisma and the React.

I've attempted to replicate get full type on prisma client within the Prisma backend but I cannot access the newly defined type within my React front end

  • Your frontend cannot query the database directly, and the question you linked shows how to get the type of a specific query on the backend, so you should have all the pieces you need. Maybe a small code example would help this question be answerable. Or perhaps you are asking "How do I share types between my backend and my frontend?" – Alex Wayne Mar 14 '23 at 21:00
  • Can you have a look at this link which demonstrates how to get the types with included relations: https://www.prisma.io/docs/concepts/components/prisma-client/advanced-type-safety/operating-against-partial-structures-of-model-types#problem-using-variations-of-the-generated-model-type – Nurul Sundarani Mar 14 '23 at 21:02
  • Essentially, I'm looking to share the type between front end and backend so that I don't have to manage multiple. The prisma docs shows how to create a custom type but I cannot access that custom type in my front end since the types generated are based on a schema.prisma – user3615797 Mar 14 '23 at 21:18
  • This _really_ depends on how your app is structured. You could have [a mono repo](https://nx.dev/) where you have a package that both your backend and frontend could import, for instance. But this doesn't have much to with Prisma at this point. – Alex Wayne Mar 14 '23 at 22:31

0 Answers0