From 8289c0c240952c5f115bbb181a3ea00a3a2611d4 Mon Sep 17 00:00:00 2001 From: abhif22 Date: Thu, 12 Sep 2019 19:40:49 +0530 Subject: [PATCH] Logging queries for which input validation fails with reason. --- graphql.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/graphql.go b/graphql.go index 2c3a9d534..6860cd40d 100644 --- a/graphql.go +++ b/graphql.go @@ -136,6 +136,12 @@ func (s *Schema) Exec(ctx context.Context, queryString string, operationName str } func (s *Schema) exec(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response { + + var ( + logFailedInputValidationQueries, anyOtherValidationError bool + errMessage string + ) + doc, qErr := query.Parse(queryString) if qErr != nil { return &Response{Errors: []*errors.QueryError{qErr}} @@ -145,7 +151,20 @@ func (s *Schema) exec(ctx context.Context, queryString string, operationName str errs := validation.Validate(s.schema, doc, variables, s.maxDepth) validationFinish(errs) if len(errs) != 0 { - return &Response{Errors: errs} + for _, err := range errs { + if err.Rule == "VariablesOfCorrectType" { + logFailedInputValidationQueries = true + errMessage = fmt.Sprintln(errMessage, "\n", err.Message) + } else if err.Rule != "" { + anyOtherValidationError = true + } + } + if anyOtherValidationError { + return &Response{Errors: errs} + } + if logFailedInputValidationQueries { + golog.Println("**************\n",errMessage, "\n", queryString, "\n**************") + } } op, err := getOperation(doc, operationName)