Skip to content

Commit

Permalink
Merge pull request #13 from dgraph-io/jatin/Fix-stringPanic
Browse files Browse the repository at this point in the history
fix(GraphQL): fix validation when we give non-string value in variable and expected type is string.
  • Loading branch information
JatinDev543 authored Feb 26, 2021
2 parents f103f8e + 4e8354a commit 6c9552e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion validator/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec
return val, nil
case ast.Scalar:
kind := val.Type().Kind()
namedType := val.Type().Name()
switch typ.NamedType {
case "Int", "Int64":
if kind == reflect.String || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 {
Expand Down Expand Up @@ -176,7 +177,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec
return val, nil
}
case "String":
if kind == reflect.String {
if namedType == "string" {
return val, nil
}

Expand Down
2 changes: 1 addition & 1 deletion validator/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type Walker struct {
Observers *Events
Schema *ast.Schema
Document *ast.QueryDocument
Variables map[string]interface{}
Variables map[string]interface{} // These variables are not coerced
validatedFragmentSpreads map[string]bool
CurrentOperation *ast.OperationDefinition
}
Expand Down

0 comments on commit 6c9552e

Please sign in to comment.