99designs / 99designs/gqlgen

Provide a configuration option to generate embedded types

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

Descrizione

This schema

```graphql
interface User {
id: ID!
email: String!
}

type Customer implements User {
id: ID!
email: String!

favoriteEmployee: Employee
}

type Employee implements User {
id: ID!
email: String!

favoriteCustomers: [Customer!]!
}
```

produces

```go
type User interface {
IsUser()
}

type Customer struct {
ID string `json:"id"`
Email string `json:"email"`
FavoriteEmployee *Employee `json:"favoriteEmployee"`
}

func (Customer) IsUser() {}

type Employee struct {
ID string `json:"id"`
Email string `json:"email"`
FavoriteCustomers []Customer `json:"favoriteCustomers"`
}

func (Employee) IsUser() {}
```

This works fine, but it's cumbersome to work with when converting from an internal type (e.g. `User`) to a `Customer` or `Employee`.

This forces me to declare those types by myself and import them in gqlgen:

```go
type User struct { // my original user type
ID string `json:"id"`
Email string `json:"email"`
}

func (User) IsUser() {}

type Customer struct {
*User
favoriteEmployee *Employee
}

type Employee struct {
*User
favoriteCustomers []Customer
}
```

```yaml
# ...
models:
User:
model: github.com/steebchen/api/prisma.User
Customer:
model: github.com/steebchen/api/prisma.Customer
Employee:
model: github.com/steebchen/api/prisma.Employee
```

This also works fine, but it's a bit annoying to define it manually and importing it manually. It also gets more cumbersome if the schema gets more complex with more user types and more complex schemas (for example when implementing multiple interfaces).

It would be great if there was an option so that embedded structs could be automatically generated.

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.