Skip to content

Commit 015365a

Browse files
Restored interface for backward compatibility
1 parent da2ce2c commit 015365a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

handler.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package handler
22

33
import (
4+
"context"
45
"encoding/json"
56
"io/ioutil"
67
"net/http"
@@ -113,7 +114,7 @@ func NewRequestOptions(r *http.Request) *RequestOptions {
113114

114115
// ContextHandler provides an entrypoint into executing graphQL queries with a
115116
// user-provided context.
116-
func (h *Handler) ContextHandler(w http.ResponseWriter, r *http.Request) {
117+
func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
117118
// get query
118119
opts := NewRequestOptions(r)
119120

@@ -123,7 +124,7 @@ func (h *Handler) ContextHandler(w http.ResponseWriter, r *http.Request) {
123124
RequestString: opts.Query,
124125
VariableValues: opts.Variables,
125126
OperationName: opts.OperationName,
126-
Context: r.Context(),
127+
Context: ctx,
127128
}
128129
result := graphql.Do(params)
129130

@@ -142,7 +143,7 @@ func (h *Handler) ContextHandler(w http.ResponseWriter, r *http.Request) {
142143

143144
// ServeHTTP provides an entrypoint into executing graphQL queries.
144145
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
145-
h.ContextHandler(w, r)
146+
h.ContextHandler(r.Context(), w, r)
146147
}
147148

148149
type Config struct {

handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestContextPropagated(t *testing.T) {
7070
*req = *req.WithContext(context.WithValue(context.Background(), "name", "context-data"))
7171
resp := httptest.NewRecorder()
7272

73-
h.ContextHandler(resp, req)
73+
h.ContextHandler(req.Context(), resp, req)
7474

7575
result := decodeResponse(t, resp)
7676

0 commit comments

Comments
 (0)