-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Reusing models, is it savvy? #78
Comments
Model generation is super handy for input objects and enums, which probably only exist in the graph. As for other types, we bind directly to our domain objects. For example we have a package for our user microservice that knows how to fetch users and returns its own User type. The user type has a few utility methods that know how to check roles etc and the graph binds directly to it (and only the fields that should be exposed). On one hand, if you bind to the model you risk someone changing it and doesn't realize they are changing the API, but custom types, enums, and a good test suite help here. On the other hand, if you don't bind to the model you end up writing a lot of boilerplate which can easily fall out of date or introduce typos but again a good test suite helps. Everything is strictly typed with the generated code (unlike the reflection based libraries), so breaks should be easy to pick up. I would recommend binding to your existing models if you have them until you cant for whatever reason. Maybe others have some thoughts? |
Yes, I agree. I would definitely define input objects and enums relating to the GraphQL business logic in there. Glad to see that domain models can still be kept outside. The code generator looks great, thanks for the effort! |
@vektah I saw you mentioned before not to bind directly to your DB models. Can you elaborate on why you wouldn't want to do that? |
I don't think that was me. Maybe #21? |
o lol, sorry the generic github user icons look so alike i didnt see that it was a different user. Thanks. |
This is not strictly an issue, just a question about usage.
I saw in the doc you can point, through types.json, to a model struct and define it yourself.
I was wondering if it's a good idea to point it, and hence use, to the same models structs we're already using for the domain logic.
The app already has a REST interface and we want to add a separate GraphQL interface to it, so it would be very handy not to have to duplicate the domain objects across the two layers.
Do you see any reasons not to?
Thanks
The text was updated successfully, but these errors were encountered: