SetErrorPresenter receives fresh r.Context(), not modified from server middleware
- 主要语言
- Go
- 星标
- 10.8k
- 派生
- 1.3k
- 平均合并
- 2 天 36 分钟
- 30 天内合并 PR
- 26
描述
### What happened?
The method `SetErrorPresenter` seems to be receiving a fresh context, a la the following code snippet:
```
if err := recover(); err != nil {
err := s.exec.PresentRecoveredError(r.Context(), err)
resp := &graphql.Response{Errors: []*gqlerror.Error{err}}
b, _ := json.Marshal(resp)
w.WriteHeader(http.StatusUnprocessableEntity)
w.Write(b)
}
```
https://github.com/99designs/gqlgen/blob/master/graphql/handler/server.go#L103-L108
However, we are mutating the context in our web middleware, and want to receive that mutated context. This is needed because we extract/inject data to align headers with context (i.e. present a unique request ID to the context, and other metadata).
### What did you expect?
The incoming context in `SetErrorPresenter` to contain the metadata from the middleware.
### Minimal graphql.schema and models to reproduce
Modify `ctx` in web middleware, compare to incoming `ctx` in `SetErrorPresenter`.
### versions
- `go run github.com/99designs/gqlgen version`? `v0.17.1`
- `go version`? `go version go1.18.1 darwin/amd64`
贡献指南
调研方向
该 issue 位于 graphql/handler/server.go 的第 103-108 行,其中 r.Context() 被传递给 PresentRecoveredError。context 应该是经过 server middleware 修改后的 context。查看 handler 在此之前如何处理 requests,以确定 middleware 在哪里修改了 context。检查 server 的 ServeHTTP 方法以及任何 context 传播过程。应添加一个 test,以验证 error presenter 接收到的是修改后的 context。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- go
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100