This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
[Proposal] Advanced Model Field configuration #1620
Labels
You can continue the conversation there. Go to discussion →
What happened?
Hey folks, I saw that there's some talk around the need for custom tags and configuration on generated model fields. For example, this PR adds support for additional tags on generated fields.
This is nice, but in my company, we actually needed a more complex configuration to limit the number of manual changes to models when having multiple dataloaders around. Each dataloader addition currently requires "moving away" from autogenerated models in order to support the changes that each "dataloading" field has.
Since gqlgen doesn’t support that we ended up creating a modelgen plugin with a secondary gqlgen-like configuration. In this config, each field has the following options:
skip
: to skip this field when generating the modelinclude
: to include this field when generating the model (opposite ofskip
and mutually exclusive)fieldType
: The type of the generated fieldfieldName
: The name of the generated field (matches gqlgen'sfieldName
, but we wanted to have all in 1 place)fieldTag
: The json tag that the model would get (could be expanded to support any tag, not justjson
ones)fieldPointer
: Whether the field should be a pointer or not (i.e. whether it's nullable)All of the above mainly serves the purpose of dataloading, where you have to make changes to certain autogenerated model fields (since the autogeneration is not aware that you're going to use a dataloader. Rather than having to do that manually (like the getting started docs suggest), we’ve opted in autogenerating everything. At the same time, this will cover a lot of other needs such as additional tags, field renamings, etc.
I was wondering whether that’s something that we’d want gqlgen to support. This would - more or less - handle all model generation needs that a user might have and would involve expanding the default field configuration, which currently has 2 options:
resolver
andfieldName
.Examples:
This would add a new field to a model:
This would change an existing field to match the data loading needs:
This would remove a field from a model:
What did you expect?
I would expect to limit the amount of changes I have to manually make. Currently, the docs tell you to copy/paste the model, but that's not optimal since it involves a lot of manual maintainance.With the solution above, no manual model maintanance is needed.
I'm personally willing to own this effort, create a PR and take it from there. What I want to check is:
Minimal graphql.schema and models to reproduce
The schema from the Getting Started docs should do. Ultimately, with my proposal, no copy/pasting would be needed to simply remove or modify a single field.
versions
The text was updated successfully, but these errors were encountered: