@@ -10,6 +10,7 @@ import (
10
10
"github.com/graphql-go/graphql"
11
11
12
12
"context"
13
+ "github.com/graphql-go/graphql/gqlerrors"
13
14
)
14
15
15
16
const (
@@ -27,6 +28,7 @@ type Handler struct {
27
28
playground bool
28
29
rootObjectFn RootObjectFn
29
30
resultCallbackFn ResultCallbackFn
31
+ customErrorFormatter func (err error ) gqlerrors.FormattedError
30
32
}
31
33
type RequestOptions struct {
32
34
Query string `json:"query" url:"query" schema:"query"`
@@ -126,11 +128,12 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
126
128
127
129
// execute graphql query
128
130
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 ,
134
137
}
135
138
if h .rootObjectFn != nil {
136
139
params .RootObject = h .rootObjectFn (ctx , r )
@@ -191,6 +194,7 @@ type Config struct {
191
194
Playground bool
192
195
RootObjectFn RootObjectFn
193
196
ResultCallbackFn ResultCallbackFn
197
+ CustomErrorFormatter func (err error ) gqlerrors.FormattedError
194
198
}
195
199
196
200
func NewConfig () * Config {
@@ -206,6 +210,7 @@ func New(p *Config) *Handler {
206
210
if p == nil {
207
211
p = NewConfig ()
208
212
}
213
+
209
214
if p .Schema == nil {
210
215
panic ("undefined GraphQL schema" )
211
216
}
@@ -217,5 +222,6 @@ func New(p *Config) *Handler {
217
222
playground : p .Playground ,
218
223
rootObjectFn : p .RootObjectFn ,
219
224
resultCallbackFn : p .ResultCallbackFn ,
225
+ customErrorFormatter : p .CustomErrorFormatter ,
220
226
}
221
227
}
0 commit comments