@@ -10,6 +10,7 @@ import (
1010 "github.com/graphql-go/graphql"
1111
1212 "context"
13+ "github.com/graphql-go/graphql/gqlerrors"
1314)
1415
1516const (
@@ -27,6 +28,7 @@ type Handler struct {
2728 playground bool
2829 rootObjectFn RootObjectFn
2930 resultCallbackFn ResultCallbackFn
31+ customErrorFormatter func (err error ) gqlerrors.FormattedError
3032}
3133type RequestOptions struct {
3234 Query string `json:"query" url:"query" schema:"query"`
@@ -126,11 +128,12 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
126128
127129 // execute graphql query
128130 params := graphql.Params {
129- Schema : * h .Schema ,
130- RequestString : opts .Query ,
131- VariableValues : opts .Variables ,
132- OperationName : opts .OperationName ,
133- Context : ctx ,
131+ Schema : * h .Schema ,
132+ RequestString : opts .Query ,
133+ VariableValues : opts .Variables ,
134+ OperationName : opts .OperationName ,
135+ Context : ctx ,
136+ CustomErrorFomatter : h .customErrorFormatter ,
134137 }
135138 if h .rootObjectFn != nil {
136139 params .RootObject = h .rootObjectFn (ctx , r )
@@ -191,6 +194,7 @@ type Config struct {
191194 Playground bool
192195 RootObjectFn RootObjectFn
193196 ResultCallbackFn ResultCallbackFn
197+ CustomErrorFormatter func (err error ) gqlerrors.FormattedError
194198}
195199
196200func NewConfig () * Config {
@@ -206,6 +210,7 @@ func New(p *Config) *Handler {
206210 if p == nil {
207211 p = NewConfig ()
208212 }
213+
209214 if p .Schema == nil {
210215 panic ("undefined GraphQL schema" )
211216 }
@@ -217,5 +222,6 @@ func New(p *Config) *Handler {
217222 playground : p .Playground ,
218223 rootObjectFn : p .RootObjectFn ,
219224 resultCallbackFn : p .ResultCallbackFn ,
225+ customErrorFormatter : p .CustomErrorFormatter ,
220226 }
221227}
0 commit comments