@@ -10,6 +10,7 @@ import (
1010 "github.com/graphql-go/graphql"
1111
1212 "context"
13+
1314 "github.com/graphql-go/graphql/gqlerrors"
1415)
1516
@@ -28,7 +29,7 @@ type Handler struct {
2829 playground bool
2930 rootObjectFn RootObjectFn
3031 resultCallbackFn ResultCallbackFn
31- formatErrorFn func (err error ) gqlerrors.FormattedError
32+ formatErrorFn func (err gqlerrors. FormattedError ) gqlerrors.FormattedError
3233}
3334
3435type RequestOptions struct {
@@ -140,10 +141,10 @@ func (h *Handler) ContextHandler(ctx context.Context, w http.ResponseWriter, r *
140141 }
141142 result := graphql .Do (params )
142143
143- if formatErrorFn := h .formatErrorFn ; formatErrorFn != nil {
144+ if formatErrorFn := h .formatErrorFn ; formatErrorFn != nil && len ( result . Errors ) > 0 {
144145 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 )
147148 }
148149 result .Errors = formatted
149150 }
@@ -202,7 +203,7 @@ type Config struct {
202203 Playground bool
203204 RootObjectFn RootObjectFn
204205 ResultCallbackFn ResultCallbackFn
205- FormatErrorFn func (err error ) gqlerrors.FormattedError
206+ FormatErrorFn func (err gqlerrors. FormattedError ) gqlerrors.FormattedError
206207}
207208
208209func NewConfig () * Config {
0 commit comments