Skip to content
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

[Proposal] Support embeding via extraFields attribute #2893

Open
tsirolnik opened this issue Feb 5, 2024 · 0 comments
Open

[Proposal] Support embeding via extraFields attribute #2893

tsirolnik opened this issue Feb 5, 2024 · 0 comments

Comments

@tsirolnik
Copy link

tsirolnik commented Feb 5, 2024

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

type User struct {
	ID   string
	Name string
	// 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant