-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integer parsed as float64 when passed in as a variable #514
Comments
@s1na This does seem like a problem with your custom type rather than a problem with the GraphQL library. Have you tried adding type Long int64
// UnmarshalGraphQL unmarshals the provided GraphQL query data.
func (b *Long) UnmarshalGraphQL(input interface{}) error {
var err error
switch input := input.(type) {
case string:
value, err := strconv.ParseInt(input, 10, 64)
*b = Long(value)
return err
case int32:
*b = Long(input)
case int64:
*b = Long(input)
case float64:
*b = Long(input)
default:
err = fmt.Errorf("unexpected type %T for Long", input)
}
return err
} |
Let me know if the above fixes the problem. If you still have issues feel free to give me a failing unit test and I'll try to make it pass. |
The reason I opened this issue is the difference in behaviour when the number is passed as part of the query vs. it being passed as a variable. In the latter case it's being parsed as a float64 which causes the error in our custom type. But I don't see why it should be parsed as float64? |
|
I am closing this issue as I don't think that it is related directly to the GraphQL library. I don't think it is worth investing time in making JSON and GraphQL parsing the same. |
Hi. We have a simple custom scalar
Long
which represents a int64 number. I.e.:A long literal in the query works ok, i.e. we can do
block(number: 1000000)
.But passing it as a variable, i.e.
query test($num: Long!) { block(number: $num) }
and then"variables": { "num": 1000000 }
fails with"unexpected type float64 for Long"
.The text was updated successfully, but these errors were encountered: