Skip to content

Commit 16bc447

Browse files
committed
Remove dependency on the unrolled/render library.
1 parent f2b24d1 commit 16bc447

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

handler.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/gorilla/schema"
1010
"github.com/graphql-go/graphql"
11-
"github.com/unrolled/render"
1211
"golang.org/x/net/context"
1312
)
1413

@@ -22,7 +21,8 @@ var decoder = schema.NewDecoder()
2221

2322
type Handler struct {
2423
Schema *graphql.Schema
25-
render *render.Render
24+
25+
pretty bool
2626
}
2727
type RequestOptions struct {
2828
Query string `json:"query" url:"query" schema:"query"`
@@ -122,8 +122,18 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
122122
}
123123
result := graphql.Do(params)
124124

125-
// render result
126-
h.render.JSON(w, http.StatusOK, result)
125+
126+
if h.pretty {
127+
w.WriteHeader(http.StatusOK)
128+
buff, _ := json.MarshalIndent(result, "", "\t")
129+
130+
w.Write(buff)
131+
} else {
132+
w.WriteHeader(http.StatusOK)
133+
buff, _ := json.Marshal(result)
134+
135+
w.Write(buff)
136+
}
127137
}
128138

129139
// ServeHTTP provides an entrypoint into executing graphQL queries.
@@ -150,11 +160,9 @@ func New(p *Config) *Handler {
150160
if p.Schema == nil {
151161
panic("undefined GraphQL schema")
152162
}
153-
r := render.New(render.Options{
154-
IndentJSON: p.Pretty,
155-
})
163+
156164
return &Handler{
157165
Schema: p.Schema,
158-
render: r,
166+
pretty: p.Pretty,
159167
}
160168
}

0 commit comments

Comments
 (0)