Skip to content

Commit

Permalink
Logging queries for which input validation fails with reason.
Browse files Browse the repository at this point in the history
  • Loading branch information
abhif22 committed Sep 12, 2019
1 parent 87522cc commit 8289c0c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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)
Expand Down

0 comments on commit 8289c0c

Please sign in to comment.