@@ -10,6 +10,7 @@ import (
10
10
"github.com/graphql-go/graphql"
11
11
12
12
"context"
13
+
13
14
"github.com/graphql-go/graphql/gqlerrors"
14
15
)
15
16
@@ -28,7 +29,7 @@ type Handler struct {
28
29
playground bool
29
30
rootObjectFn RootObjectFn
30
31
resultCallbackFn ResultCallbackFn
31
- formatErrorFn func (err error ) gqlerrors.FormattedError
32
+ formatErrorFn func (err gqlerrors. FormattedError ) gqlerrors.FormattedError
32
33
}
33
34
34
35
type RequestOptions struct {
@@ -140,10 +141,10 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
140
141
}
141
142
result := graphql .Do (params )
142
143
143
- if formatErrorFn := h .formatErrorFn ; formatErrorFn != nil {
144
+ if formatErrorFn := h .formatErrorFn ; formatErrorFn != nil && len ( result . Errors ) > 0 {
144
145
formatted := make ([]gqlerrors.FormattedError , len (result .Errors ))
145
- for i , err := range result .Errors {
146
- formatted [i ] = formatErrorFn (err . OriginalError () )
146
+ for i , formattedError := range result .Errors {
147
+ formatted [i ] = formatErrorFn (formattedError )
147
148
}
148
149
result .Errors = formatted
149
150
}
@@ -202,7 +203,7 @@ type Config struct {
202
203
Playground bool
203
204
RootObjectFn RootObjectFn
204
205
ResultCallbackFn ResultCallbackFn
205
- FormatErrorFn func (err error ) gqlerrors.FormattedError
206
+ FormatErrorFn func (err gqlerrors. FormattedError ) gqlerrors.FormattedError
206
207
}
207
208
208
209
func NewConfig () * Config {
0 commit comments