diff --git a/handler.go b/handler.go index 23d12f2..4494ee9 100644 --- a/handler.go +++ b/handler.go @@ -20,7 +20,7 @@ const ( type Handler struct { Schema *graphql.Schema - + pretty bool } type RequestOptions struct { @@ -129,7 +129,9 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r * } result := graphql.Do(params) - + // use proper JSON Header + w.Header().Add("Content-Type", "application/json") + if h.pretty { w.WriteHeader(http.StatusOK) buff, _ := json.MarshalIndent(result, "", "\t") @@ -138,7 +140,7 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r * } else { w.WriteHeader(http.StatusOK) buff, _ := json.Marshal(result) - + w.Write(buff) } } diff --git a/handler_test.go b/handler_test.go index 7c8a60b..ea73d2a 100644 --- a/handler_test.go +++ b/handler_test.go @@ -10,10 +10,10 @@ import ( "strings" "testing" + "context" "github.com/graphql-go/graphql" "github.com/graphql-go/graphql/testutil" "github.com/graphql-go/handler" - "context" ) func decodeResponse(t *testing.T, recorder *httptest.ResponseRecorder) *graphql.Result {