From 447a0647b2a6f6ede6190166a5aeb2f22e06c21b Mon Sep 17 00:00:00 2001 From: Niklas Date: Sat, 14 Aug 2021 01:33:42 +0200 Subject: [PATCH] logging on gql errors --- internal/httpServer.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/httpServer.go b/internal/httpServer.go index 4e96f49..6981b59 100644 --- a/internal/httpServer.go +++ b/internal/httpServer.go @@ -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) {