Skip to content

Commit

Permalink
Merge pull request #27 from yookoala/header
Browse files Browse the repository at this point in the history
Use "applicaiton/json" as content type in header
  • Loading branch information
chris-ramon authored Aug 24, 2017
2 parents fab5288 + e2b4a68 commit 43051ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (

type Handler struct {
Schema *graphql.Schema

pretty bool
}
type RequestOptions struct {
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 43051ba

Please sign in to comment.