Skip to content

Commit

Permalink
validator: better error message when InputObject is not a map
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmithr committed Jun 14, 2024
1 parent 8bb54d3 commit da5aafd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion validator/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (v *varValidator) validateVarType(typ *ast.Type, val reflect.Value) (reflec
return val, gqlerror.ErrorPathf(v.path, "cannot use %s as %s", kind.String(), typ.NamedType)
case ast.InputObject:
if val.Kind() != reflect.Map {
return val, gqlerror.ErrorPathf(v.path, "must be a %s", def.Name)
return val, gqlerror.ErrorPathf(v.path, "must be a %s, not a %s", def.Name, val.Kind())
}

// check for unknown fields
Expand Down
2 changes: 1 addition & 1 deletion validator/vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestValidateVars(t *testing.T) {
_, gerr := validator.VariableValues(schema, q.Operations.ForName(""), map[string]interface{}{
"var": "hello",
})
require.EqualError(t, gerr, "input: variable.var must be a InputType")
require.EqualError(t, gerr, "input: variable.var must be a InputType, not a string")
})

t.Run("defaults", func(t *testing.T) {
Expand Down

0 comments on commit da5aafd

Please sign in to comment.