99designs / 99designs/gqlgen

SetErrorPresenter receives fresh r.Context(), not modified from server middleware

Đang mở
#2,241 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Go
Star
10.8k
Fork
1.3k
Merge trung bình
2 ngày 36 phút
Pull request đã merge (30 ngày)
26

Mô tả

### 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`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Issue nằm trong graphql/handler/server.go, ở các dòng 103-108, nơi r.Context() được truyền vào PresentRecoveredError. Context phải là context đã được server middleware sửa đổi. Hãy xem handler xử lý các request như thế nào trước điểm đó để xác định middleware sửa đổi context ở đâu. Kiểm tra phương thức ServeHTTP của server và mọi việc truyền context. Một test nên xác minh rằng error presenter nhận được context đã được sửa đổi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
go
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.