How to deal with integer overflow when using variables
Hi, I have been trying a work-around when dealing with integer values for ranges above int32. I've looked at Scalars for the BigInt type but I am not sure how can I incorporate something like this in this package.
Here's what my variable looks like:
// max range for int32 is 2,147,483,647
myId := 3211136557
v := map[string]any{
"id": graphql.Int(myId) // the value for this will be a random int32 since it is overflowing
}
For now, what I'm doing is statically indicating the ID in my query but it would be nice if it could be dynamic.
Thanks
graphql.Int is documented as being able to represent values between -(2^31) and 2^31 - 1. It corresponds to the Int scalar in the GraphQL specification: https://spec.graphql.org/October2021/#sec-Int.
Do you own the schema and can pick the type of the ID? If so, consider using https://spec.graphql.org/October2021/#sec-ID or another string scalar instead of Int:
v := map[string]any{
"id": graphql.ID("3211136557")
}
Do you own the schema and can pick the type of the ID? If so, consider using https://spec.graphql.org/October2021/#sec-ID or another string scalar instead of
Int:v := map[string]any{ "id": graphql.ID("3211136557") }
Unfortunately not, I've just tried this just to see what would be the result:
Type mismatch on variable $id and argument ids ([ID!]! / [Int])
So i'll just stick to hard coding it for now, thanks for the response @dmitshur and this cool package for a graphql client 💯