graphql-import
graphql-import copied to clipboard
Idea: Redesign type definitions/code generation to avoid repetitive type definitions on server and prisma side
Hi, I have an idea/suggestion. I find it a little bit tedious to always copy/paste my graphql datamodels from the prisma backend to the server graphql type definition file, 90% of my models are reused anyway. Wouldnt it be possible to simply add an anotation like "expose" and "private" to the prisma type definitions and their parameters and include the types in the code generation process? with default to "private", this would not change the current behavior and could be handy to quickly export the types you want to expose from prisma in a DRY manner without having to copy paste the common types all the time. additionally, it might be nice to also make overriding these in the server portion of the app a more conscious process with an "extends" or "overrides" annotation or keyword on altering type definitions.
I agree. As 90% is reused, it might be convenient to set them as public by default and to add a directive like @private
to not expose some field.
Something like:
type User {
id: ID! @unique
email: String! @unique
password: String! @private
role: UserRole!
}
I like the idea of supporting directives to decide with parts of the schema to put in the final schema part. I think the process should be similar to how graphql-import
currently processes the schema, but instead of import
statements it would look at directives. So you would still have an input file and output file, but the processing would happen on different conditions.
The only problem is, that the prisma backend will overwrite the generated schema every time you deploy, so depending on whether or not it preserves custom directives, this might also need a change on the prisma side. @marktani Are custom directives ignored/preserved, or removed by Prisma?
I agree with @kbrandwijk.
In my case that would make things way easier.
My current understanding is that custom directives in datamodel.graphql
are ignored, so they are not part of the final schema.
Can you detail how a custom directive in datamodel.graphql
would translate to custom directives in the automatically generated prisma.graphql
? That's not a trivial question.
I think is solved with Prisma Nexus and can be closed. Thanks for the feedback