-
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
Custom struct tags #463
Comments
We are going to address model generation the release after next when we look at plugins. Our plan is to pull model generation out into a plugin by itself that you could then add features like this to. As you point out, the meanwhile solution would be to have these tags manually on models and map them through to gqlgen. Not ideal, but perhaps you could add another codegen step with a custom script in the meantime? |
This could be great for generating Gorm compatible models (setting things like default values). type Model struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()"`
} |
+1
|
model generation is now a plugin, which means you can write your own. All thats missing is docs, and a 0.8 release. |
You can now do this by replacing the model generator plugin, see https://gqlgen.com/reference/plugins/ |
Hi all, having reviewed the documentation for model generation as a plugin, I wasn't able to find the correct location to create custom struct tags. Would very much appreciate some help. Thank you! |
Bump. |
Need it too. Is this feature already released? Could anyone provide link to doc? Thanks! |
We need custom tags too. Where can we find more details and the documentation? |
+1 need documentation |
+1 need documentation! |
for anyone who also has this issue, here is a workaround I used: copy both
|
Another example of this for people who find this issue and do not find the proper documentation is here: https://gqlgen.com/recipes/modelgen-hook/ For the simple use case using the code located at the gqlgen docs linked above should solve the issue. For some of the more complex use cases you could expand this to accept directives and do something similar to what AienTech has done above. I like using the method in the docs because it adjusts the models at generation time. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@AienTech your solution works amazingly fine! What does not work is Maybe the step 3 is wrong? Thanks a lot for your help. |
Ignore this code here
Then add this line in the schema file. |
Just started to use gqlgen to add gorm flags and I also have the problem that the auto binding doesn't work with @AienTech `s solution. It will complain that the model is redeclared. |
@AienTech 's solution worked for me flawlessly. Thank you! |
@frederikhors |
Expected Behaviour
I would like to add custom tags to struct; which would be read and wrote by gqlgen generator.
For example: I have input declared in graphql schema, where I wish to define sanitization, validation and probably some convert.
All I'm saying is: let us define custom tags, you don't even need to know what they are for :)
Actual Behavior
Only
json:"..."
tag is generated.Minimal graphql.schema and models to reproduce
Lets say we have input that looks something like this:
or
and gqlgen generator would output struct that look like this:
I know there is already a solution for modifying model struct, but for overwriting 300+ structs for only tag addition is really not a good clean solution.
The text was updated successfully, but these errors were encountered: