MichalLytek / typegraphql-prisma

Prisma generator to emit TypeGraphQL types and CRUD resolvers from your Prisma schema
https://prisma.typegraphql.com
MIT License
887 stars 113 forks source link

Code-first approach using classes with decorators as a single source of truth #9

Open FluorescentHallucinogen opened 3 years ago

FluorescentHallucinogen commented 3 years ago

From https://github.com/MichalLytek/typegraphql-prisma/issues/1#issue-714873665:

And in the near feature - when Prisma SDK will be ready - the typegraphql-prisma integration will also allow to use a code-first approach to build a schema.prisma and GraphQL schema at once, using classes with decorators as a single source of truth. Stay tuned! 💪

Are we there yet? Is the Prisma SDK ready? If not, what exactly is missing?

Recently I've been chatting with @divyenduz and he asked to open issue(s) about this in Prisma repo(s), so the Prisma team would have them in mind.

MichalLytek commented 3 years ago

If not, what exactly is missing?

I think that everything 😅

Prisma SDK aims to be abstraction level over DMMF and a schema printer. Without this tools, all we can do is to manually handcraft the schema.prisma file from decorator metadata 🤯

MitchellMonaghan commented 3 years ago

Hi recently started using this. Was wondering if this will also add class-validator support? Also will this end up being a complete rewrite of this package (no longer using prisma model as input and instead our class model?) or will the class model generate prisma to leverage existing code?

To add validator support then would need to be added to the generated prisma model though comment tags or something like that (similar to field rename). I started writing code myself to add validator support but figured I should start a conversation about it.

I don't think prisma has plans for validation themselves.

MichalLytek commented 3 years ago

Also will this end up being a complete rewrite of this package (no longer using prisma model as input and instead our class model?) or will the class model generate prisma to leverage existing code?

Class model has to generate prisma schema file to allow migrate, studio and other Prisma tools working correctly.

The code-first approach still gonna need a prisma generator to generate crud resolvers and inputs classes.

Was wondering if this will also add class-validator support?

I'm going to create a RFC about the way of extending the class types with some runtime, non-static behavior, as comment docs aka prisma attributes are a string and have limitations.