logging on gql errors

This commit is contained in:
Niklas 2021-08-14 01:33:42 +02:00
parent 7253a9195d
commit 447a0647b2

View File

@ -10,6 +10,7 @@ import (
"github.com/graph-gophers/dataloader"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/handler"
"github.com/minio/minio-go/v7"
@ -23,6 +24,15 @@ func initHttp(resolveContext context.Context, schema graphql.Schema) error {
Pretty: true,
GraphiQL: false,
Playground: true,
FormatErrorFn: func(err error) gqlerrors.FormattedError {
switch err := err.(type) {
case gqlerrors.FormattedError:
log.Error("GQL: ", err.Message)
case *gqlerrors.Error:
log.Errorf("GQL: '%s' at '%v'", err.Message, err.Path)
}
return gqlerrors.FormatError(err)
},
})
http.HandleFunc("/graphql", func(rw http.ResponseWriter, r *http.Request) {