-
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
Tag mapping #212
Comments
Model generation isn't really set up to cover every use case. If you want something unusual you'll have to build the models yourself and reference them in the config. At some point in the future the templates might be configurable, but for now there are other features that have a higher priority (and have less conflicting requirements from different people) |
Unfortunately many databases use properties starting with underscore (MongoDB also uses _id) and this practice collides with Go's marshalling and unmarshalling process. |
You are free to build the struct yourself however you want: type User struct {
ID string json:"_id"
Key string json:"_key"
Rev string json:"_rev"
} and bind it to a graphql object from schema type User {
id: ID!
key: ID!
rev: String!
} with the config: models:
User:
model: github.com/my/app/models.User This shouldn't a blocker for anything, it just means you need to write out the structs yourself. |
Yes I figured, however we use a couple of models with more than a hundred fields, and we will then have to manually keep them in sync with the GraphQL models (which have the same number of fields) and the error margin increases this way (that's why we found the autogenerate feature really nice). We may try to provide a PR. Maybe an extra field in the config yaml file named |
Is this Issue over? |
@vvakame You can use inline-config-with-directives, fox example:
|
In every model for my database I have these 3 fields:
In order for the marshalling and unmarshalling to work correctly I need to place these three tags on each golang struct:
(Note that these three properties are required by the database, so I cannot change the tags)
When I autogenerate the graphql type the json tags are also autogenerated. The issue here is that the database variables start with underscore, and all types in Go that start with an underscore are not exported (thus I can't declare a field to start with an underscore, so as that I could have an autogenerated json tag starting with underscore)
Is there any way to bypass this issue? In case there isn't, would it be possible to have an entry in the configuration file, where we could map certain fields with certain tags (and have the rest autogenerated)?
GraphQL type:
Autogenerated Go struct:
The text was updated successfully, but these errors were encountered: