99designs / 99designs/gqlgen

usage of field resolver when it is used in multiple resolvers

未关闭
#1,448 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
10.8k
派生
1.3k
平均合并
2 天 36 分钟
30 天内合并 PR
26

描述

### What happened?
Followed this link https://github.com/99designs/gqlgen#using-explicit-resolvers to have field based resolvers so that they are fetched only when they are asked for.
```
Todo:
fields:
user:
resolver: true
```
Below is the model, and the two queries which returns this model.
```
type Todo {
id(version1: String!): ID! @directive1
text: String!
done: Boolean! @deprecated(reason: "some reason")
user: User!
}

type Query {
todos(version: String!): [Todo!]!
todos_ex(version: String!): [Todo!]!
}
```
On performing `go run github.com/99designs/gqlgen generate`, below is the resolver got added.
```
func (r *todoResolver) User(ctx context.Context, obj *model.Todo) (*model.User, error) {
```

But, I have a requirement to perform different operations in `User` `todoResolver` based on the type of query resolver which it is called.
Same model `Todo` might be returned in mutations as well.

It would be helpful if there are steps that I can do to achieve this.
### What did you expect?

I expected a seperate field resolver for each query/mutation/subscription resolver it is returned from (or) any other way to achieve this.

### Minimal graphql.schema and models to reproduce

### versions
- `gqlgen version`?
- `go version`?
go1.14.2
- dep or go modules?

贡献指南

打开贡献指南

调研方向

这个 issue 涉及 gqlgen 的字段 resolver 生成。查看生成的 resolver.go 文件中的 resolver 代码,尤其是 todoResolver 的 User 方法。通过检查 gqlgen.yml 配置和 graphql schema,了解 gqlgen 的代码生成方式。目标是修改 resolver,使其根据父级 query 或 mutation 采取不同的行为。查看 gqlgen 关于字段 resolver 的文档以及 resolver 的调用方式对应的源代码。

由索引模型根据 Issue 内容生成。

评估

技术栈
go
领域
api, backend
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。