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? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
@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')
export class UserModel extends BaseModel implements User {
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 feature typegraphql-prisma
There is also an typegraphql integration for nestjs typegraphql-nestjs with some caveats. |
Beta Was this translation helpful? Give feedback.
-
@marcjulian |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
With prisma, I use the generated models(types) from prisma client. Why need
to 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>
|
Beta Was this translation helpful? Give feedback.
@Skona27 Hi, thanks 👍 I hope I can answer your question.
Yes currently the code requires duplicates between the prisma schema and the graphql schema.
schema.prisma
describes the model and thus the table created for this model.user.model.ts
and any other models describes the response value of youruser
type for your GraphQL queriesHow to resolve the duplicates for now?
It is currently necessary to have duplicate code once in
schema.prisma
and once for your GraphQL schema.One idea would be to implement
User
from prisma client for your graphql model to always keep those prisma and graphql models in sync.