You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose I want to add an embedded struct to a generated model, as far as I understand, this is not possible at the moment.
My proposal is to allow embedding via a modification to the extraFields attribute of models in the gqlgen.yml file.
By adding an attribute of, for example - embedded: true the extra field will only embed the type instead of adding it as an attribute to the struct.
So the following example -
models:
User:
extraFields:
Session:
description: "A Session used by this user"type: "github.com/author/mypkg.Session"embedded: True
will generate
typeUserstruct {
IDstringNamestring// A Session used by this user.
mypkg.Session
}
This solution will allow to add out of the box support for embedding with , IMO, minimal required changes.
This is especially useful when using 3rd party libraries such as gorm, i.e users of gorm frequently use the gorm.Model type by embedding into their model definitions.
If this sounds like something is desired I will be more than happy to try and create a pr for that.
The text was updated successfully, but these errors were encountered:
Suppose I want to add an embedded struct to a generated model, as far as I understand, this is not possible at the moment.
My proposal is to allow embedding via a modification to the extraFields attribute of models in the
gqlgen.yml
file.By adding an attribute of, for example -
embedded: true
the extra field will only embed the type instead of adding it as an attribute to the struct.So the following example -
will generate
This solution will allow to add out of the box support for embedding with , IMO, minimal required changes.
This is especially useful when using 3rd party libraries such as gorm, i.e users of gorm frequently use the
gorm.Model
type by embedding into their model definitions.If this sounds like something is desired I will be more than happy to try and create a pr for that.
The text was updated successfully, but these errors were encountered: