Skip to content
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

How to deal with integer overflow when using variables #120

Open
gams-temark opened this issue Feb 12, 2024 · 2 comments
Open

How to deal with integer overflow when using variables #120

gams-temark opened this issue Feb 12, 2024 · 2 comments

Comments

@gams-temark
Copy link

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

@dmitshur
Copy link
Member

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")
}

@gams-temark
Copy link
Author

gams-temark commented Feb 12, 2024

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 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants