Skip to content

Commit

Permalink
Merge pull request 99designs#1215 from ddouglas/master
Browse files Browse the repository at this point in the history
Adding Missing Header to response
  • Loading branch information
lwc authored Jul 10, 2020
2 parents fbe6e39 + 62aaef3 commit 9b01357
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions graphql/handler/transport/http_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func (h GET) Supports(r *http.Request) bool {
}

func (h GET) Do(w http.ResponseWriter, r *http.Request, exec graphql.GraphExecutor) {
w.Header().Set("Content-Type", "application/json")

raw := &graphql.RawParams{
Query: r.URL.Query().Get("query"),
OperationName: r.URL.Query().Get("operationName"),
Expand Down
6 changes: 6 additions & 0 deletions graphql/handler/transport/http_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func TestGET(t *testing.T) {
assert.Equal(t, `{"data":{"name":"test"}}`, resp.Body.String())
})

t.Run("has json content-type header", func(t *testing.T) {
resp := doRequest(h, "GET", "/graphql?query={name}", ``)
assert.Equal(t, "application/json", resp.Header().Get("Content-Type"))
})

t.Run("decode failure", func(t *testing.T) {
resp := doRequest(h, "GET", "/graphql?query={name}&variables=notjson", "")
assert.Equal(t, http.StatusBadRequest, resp.Code, resp.Body.String())
Expand All @@ -42,4 +47,5 @@ func TestGET(t *testing.T) {
assert.Equal(t, http.StatusNotAcceptable, resp.Code, resp.Body.String())
assert.Equal(t, `{"errors":[{"message":"GET requests only allow query operations"}],"data":null}`, resp.Body.String())
})

}

0 comments on commit 9b01357

Please sign in to comment.