Control Getter generation for types and/or fields
- Dominant language
- Go
- Stars
- 10.8k
- Forks
- 1.3k
- Avg merge
- 2d 36m
- Merged PRs (30d)
- 26
Description
### What happened?
- Getter generation is useful, since it enables our business logic to depend on interfaces implemented by gqlgen structs, instead of the structs themselves
- `omit_getters: false` in the configuration toggles getter generation globally, and is useful because we want to generate getters for _almost_ all types
- some getters are not desired, and some cause compilation errors
```
go run github.com/99designs/gqlgen generate -config gqlgen.yml
merging type systems failed: unable to bind to interface: path/to/model.Team does not satisfy the interface path/to/model.GroupOwner
exit status 1
make: *** [gen-gql-v1] Error 1
```
### What did you expect?
- `groups` is a nested query resolver, and it has an input argument, so I am not sure how `GetGroups` could be a method with no arguments.
- I would expect nested resolvers to aways be omitted from the generated interface
- I would like to use something like `goModel(omitGetters: true)` to toggle getter generation for the type
- this should override the global `omit_getters` setting
- I would like to use something like `goField(omitGetter: true)` to toggle getter generation for the field
- this should override the `goModel` and global `omit_getters` settings
### Minimal graphql.schema and models to reproduce
```graphql
interface GroupOwner {
groups(input: GroupsInput): [String]!
}
type Team implements GroupOwner {
id: ID!
groups(input: GroupsInput): [String]!
}
```
```golang
type GroupOwner interface {
IsGroupOwner()
GetGroups() []string
}
// defined manually in the models package, thus GetGroups() is not generated and Team cannot satisfy the GroupOwner interface
type Team struct {
ID string `json:"id"`
}
func (Team) IsGroupOwner() {}
```
### versions
- `go run github.com/99designs/gqlgen version`?
- `v0.17.34`
- `go version`?
- `go version go1.19.3 darwin/arm64`
Contributor guide
Assessment
This issue has not been assessed yet.