Skip to content

Commit 6c9552e

Browse files
authored
Merge pull request #13 from dgraph-io/jatin/Fix-stringPanic
fix(GraphQL): fix validation when we give non-string value in variable and expected type is string.
2 parents f103f8e + 4e8354a commit 6c9552e

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

validator/vars.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec
145145
return val, nil
146146
case ast.Scalar:
147147
kind := val.Type().Kind()
148+
namedType := val.Type().Name()
148149
switch typ.NamedType {
149150
case "Int", "Int64":
150151
if kind == reflect.String || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 {
@@ -176,7 +177,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec
176177
return val, nil
177178
}
178179
case "String":
179-
if kind == reflect.String {
180+
if namedType == "string" {
180181
return val, nil
181182
}
182183

validator/walk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type Walker struct {
5959
Observers *Events
6060
Schema *ast.Schema
6161
Document *ast.QueryDocument
62-
Variables map[string]interface{}
62+
Variables map[string]interface{} // These variables are not coerced
6363
validatedFragmentSpreads map[string]bool
6464
CurrentOperation *ast.OperationDefinition
6565
}

0 commit comments

Comments
 (0)