-
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
POC: Generated model extra fields #2638
Conversation
@StevenACoffman Hi, Steven! What do you think about this tiny feature? |
@auvn any chance for a follow-up with some docs about this feature? |
Sorry for the delay! This is great! I would love some docs if you get a chance. |
Yeah, of course, I'll rise another PR for docs. |
type ModelExtraField struct { | ||
Type string `yaml:"type"` | ||
IsPointer bool `yaml:"isPointer"` | ||
OverrideTags string `yaml:"overrideTags"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would ideally like this to contain another string field Description
that would set the goDoc comment for the field, if possible.
@auvn We have an internal plugin that did a similar thing, in a worse way, but the config looked a little different:
The delay in my reviewing (or even commenting) was that I was really trying to find the time to reconcile your code with that, but I just have been too slammed at my dayjob. In that plugin, we support the builtin basic types (like string or int64), named types For example, the following are valid types:
I very much like that in your implementation this functionality is just baked in to modelgen, rather than using a plugin that wraps modelgen. However, If I could add one thing from our wrapper plugin version, is that over there the config supports setting the GoDoc comment for the generated field ( I hacked up the internal plugins we have at Khan and stuck them in a public repo over here so you can see what I'm talking about (if that's helpful): https://github.com/StevenACoffman/gqlgen-plugins/blob/main/extra_fields.go |
@StevenACoffman you reference is good! In this case Im going to port the missing functionality and bake it in gqlgen. Thanks! |
See follow-up #2655 |
Whenever I was implementing something using gqlgen I was facing the need of several extra fields for intermediate generated go objects in order to pass different data from the parent resolver to the children. Yes, I can define a whole model as a separate object, but it's easier to append one or two extra fields instead.
This PR implements ability to define any extra fields for a generatable models. So they are available to consume by resolver implementations.
TLDR:
the following config
turns out into the following generated model where extra fields are not exposed to the API consumers but only for resolvers.
Any suggestions about config improvements are appreciated.
I have: