Skip to content

Commit 8289c0c

Browse files
author
abhif22
committed
Logging queries for which input validation fails with reason.
1 parent 87522cc commit 8289c0c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

graphql.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ func (s *Schema) Exec(ctx context.Context, queryString string, operationName str
136136
}
137137

138138
func (s *Schema) exec(ctx context.Context, queryString string, operationName string, variables map[string]interface{}, res *resolvable.Schema) *Response {
139+
140+
var (
141+
logFailedInputValidationQueries, anyOtherValidationError bool
142+
errMessage string
143+
)
144+
139145
doc, qErr := query.Parse(queryString)
140146
if qErr != nil {
141147
return &Response{Errors: []*errors.QueryError{qErr}}
@@ -145,7 +151,20 @@ func (s *Schema) exec(ctx context.Context, queryString string, operationName str
145151
errs := validation.Validate(s.schema, doc, variables, s.maxDepth)
146152
validationFinish(errs)
147153
if len(errs) != 0 {
148-
return &Response{Errors: errs}
154+
for _, err := range errs {
155+
if err.Rule == "VariablesOfCorrectType" {
156+
logFailedInputValidationQueries = true
157+
errMessage = fmt.Sprintln(errMessage, "\n", err.Message)
158+
} else if err.Rule != "" {
159+
anyOtherValidationError = true
160+
}
161+
}
162+
if anyOtherValidationError {
163+
return &Response{Errors: errs}
164+
}
165+
if logFailedInputValidationQueries {
166+
golog.Println("**************\n",errMessage, "\n", queryString, "\n**************")
167+
}
149168
}
150169

151170
op, err := getOperation(doc, operationName)

0 commit comments

Comments
 (0)