99designs / 99designs/gqlgen

What is the best way to pass variables between query and response object field resolver ?

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

描述

### What happened?
I want to know best practice to pass variables between query and response object field resolver.

### What did you expect?
I need sync way for passing variables between query and response object field resolver.
I know about [OperationContext](https://github.com/99designs/gqlgen/blob/master/graphql/context_operation.go), but it is basic map, so I have some concurrent problems.
```
tmp := "Hello world"
graphql.GetOperationContext(ctx).Variables["HelloWorld"] = &tmp
tmp2 := graphql.GetOperationContext(ctx).Variables["HelloWorld"].(*string)
```
### Minimal graphql.schema and models to reproduce
```
Object {
ID: ID!
isOK: Boolean! @goField(forceResolver: true)
}

type Query {
Objects: [Object!]
}
```
### versions
- `go run github.com/99designs/gqlgen version` 17.41
- `go version` go1.19.2

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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