Skip to content

Commit

Permalink
remove support of string -->int32 coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
JatinDev543 committed Mar 15, 2021
1 parent 6c9552e commit 06de469
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion validator/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec
namedType := val.Type().Name()
switch typ.NamedType {
case "Int", "Int64":
if kind == reflect.String || kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 {
if kind == reflect.Int || kind == reflect.Int32 || kind == reflect.Int64 || (namedType == "string" && typ.NamedType == "Int64") || namedType == "Number" {
var errIntCoerce error
var valString string
if kind == reflect.String {
Expand Down
8 changes: 8 additions & 0 deletions validator/vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ func TestValidateVars(t *testing.T) {
require.EqualError(t, gerr, "input: variable.var cannot use float64 as Int")
})

t.Run("error for invalid coercing, String -> Int ", func(t *testing.T) {
q := gqlparser.MustLoadQuery(schema, `query foo($var: Int!) { intArg(i: $var) }`)
_, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{
"var": "18",
})
require.EqualError(t, gerr, "input: variable.var cannot use string as Int")
})

t.Run("out of range error for Int", func(t *testing.T) {
q := gqlparser.MustLoadQuery(schema, `query foo($var: Int!) { intArg(i: $var) }`)
_, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{
Expand Down

0 comments on commit 06de469

Please sign in to comment.