graphql-import icon indicating copy to clipboard operation
graphql-import copied to clipboard

Idea: Redesign type definitions/code generation to avoid repetitive type definitions on server and prisma side

Open moritzmorgenroth opened this issue 7 years ago • 5 comments

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.

moritzmorgenroth avatar Jan 23 '18 10:01 moritzmorgenroth

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!
}

emipc avatar Jan 23 '18 10:01 emipc

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?

kbrandwijk avatar Jan 23 '18 16:01 kbrandwijk

I agree with @kbrandwijk.

In my case that would make things way easier.

jvbianchi avatar Jan 29 '18 19:01 jvbianchi

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.

marktani avatar Jan 29 '18 22:01 marktani

I think is solved with Prisma Nexus and can be closed. Thanks for the feedback

moritzmorgenroth avatar Apr 11 '19 07:04 moritzmorgenroth