Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
moritzmorgenroth opened this issue Jan 23, 2018 · 5 comments

Comments

@moritzmorgenroth
Copy link

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.

@emipc
Copy link

emipc commented Jan 23, 2018

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

@kbrandwijk
Copy link
Contributor

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?

@jvbianchi
Copy link

I agree with @kbrandwijk.

In my case that would make things way easier.

@marktani
Copy link

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.

@moritzmorgenroth
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants