- Notifications
You must be signed in to change notification settings - Fork360
Duplication between prisma schema and models#446
-
Hi! I've noticed that some of the code is duplicated between prisma schema definitions and nest js models. And also in Why is that necessary? Can't we somehow generate schema from models, or other way around? |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
@Skona27 Hi, thanks 👍 I hope I can answer your question.
Yes currently the code requires duplicates between the prisma schema and the graphql schema.
- Database schema:
schema.prismadescribes the model and thus the table created for this model. - GraphQL schema:
user.model.tsand any other models describes the response value of yourusertype for your GraphQL queries
How to resolve the duplicates for now?
It is currentlynecessary to have duplicate code once inschema.prisma and once for your GraphQL schema.
One idea would be to implementUser from prisma client for your graphql model to always keep those prisma and graphql models in sync.
import{User}from'@prisma/client';import{P…
Replies: 4 comments 2 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
@Skona27 Hi, thanks 👍 I hope I can answer your question. Yes currently the code requires duplicates between the prisma schema and the graphql schema.
How to resolve the duplicates for now? One idea would be to implement import{User}from'@prisma/client';import{PostModel}from'../post/post.model.ts';@ObjectType('User')exportclassUserModelextendsBaseModelimplementsUser{email:string; @Field({nullable:true})firstname:string; @Field({nullable:true})lastname:string;role:Role; @HideField()password:string;posts:PostModel[];} Another option might be in the featuretypegraphql-prisma
There is also an typegraphql integration for nestjstypegraphql-nestjs with somecaveats. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Anothre option could behttps://github.com/unlight/prisma-nestjs-graphql which is similar tohttps://github.com/MichalLytek/typegraphql-prisma, but works with NestJS GraphQL Module. |
BetaWas this translation helpful?Give feedback.
All reactions
-
@marcjulian |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
its been a while since asked. is there now a way to not have duplicate data ? i thought it be easier that classes generate prisma DSL but it does not seem to be a thing. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Yes, there a way to avoid duplicated data, just don't use prisma with NestJS. I know this is probably the most disappointing answer, but it seems like the technology isn't really compatible with each other and it's just getting exclusive set. TypeORM seems to be more fitting package (but less hyped atm). |
BetaWas this translation helpful?Give feedback.
All reactions
-
With prisma, I use the generated models(types) from prisma client. Why needto generate models again? …On Wed, 23 Nov 2022, 8:24 pm Łukasz Sitarski, ***@***.***> wrote: Yes, there a way to avoid duplicated data, just don't use prisma with NestJS. I know this is probably the most disappointing answer, but it seems like the technology isn't really compatible with each other and it's just getting exclusive set. TypeORM seems to be more fitting package (but less hyped atm). — Reply to this email directly, view it on GitHub <#446 (reply in thread)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AIMV5QNBTY5XOZATKSFAI4TWJZHMVANCNFSM44FFJAEA> . You are receiving this because you are subscribed to this thread.Message ID: <notiz-dev/nestjs-prisma-starter/repo-discussions/446/comments/4218694 @github.com> |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #427 on May 04, 2021 16:18.