99designs / 99designs/gqlgen

[Proposal] Support embeding via extraFields attribute

Aperta
#2,893 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
10.8k
Fork
1.3k
Merge medio
2g 36m
PR unite (30g)
26

Descrizione

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 -
```yaml
models:
User:
extraFields:
Session:
description: "A Session used by this user"
type: "github.com/author/mypkg.Session"
embedded: True
```

will generate
```go
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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.