Control Getter generation for types and/or fields
- 主要语言
- Go
- 星标
- 10.8k
- 派生
- 1.3k
- 平均合并
- 2 天 36 分钟
- 30 天内合并 PR
- 26
描述
### 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`
贡献指南
调研方向
这个 issue 涉及 gqlgen 为 getter 方法生成代码。查看 codegen 包中的配置处理逻辑,可能重点在模型绑定和接口满足的相关部分。用户希望通过按类型和按字段的指令来控制 getter 的生成,并覆盖全局 omit_getters 设置。首先检查 goModel 和 goField 指令的处理方式,以及 getter 方法在哪里生成。检查 Team 不满足 GroupOwner 的错误,以了解当前的生成逻辑。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- go, graphql
- 领域
- api, backend, devtools
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100