gqlgen
gqlgen copied to clipboard
Gqlgen won't allow int values
What happened?
If my schema expects an Int
such as:
extend type Query {
calculateFees(enteredAmountCents: Int!): CalculateFeesResult!
}
And consequently my resolver is bound to an int
for enteredAmountCents
, if the query includes the argument in-line, it works fine. In other words this works:
query {
calculateFees(enteredAmountCents: 100) {
totalAmount
}
}
HOWEVER if the argument is provided by variable, it fails on the basis that float64 is not an int
. So this fails:
query CalculateFees($enteredAmount: Int!) {
calculateFees(enteredAmountCents: $enteredAmount) {
totalAmount
}
}
// Variables
{
"enteredAmount": 100
}
The above works fine if I change the schema to take in Float
rather than Int
, but that means I cannot enforce integers... Is there any way to enforce that I want an int using gqlgen?
What did you expect?
Int
works as expected, and that it can parse a number coming in via json to int
without erroring because it isn't a float. This was raised in #664, but it was marked solved. I don't think it's solved. I am still not sure how I can have an int
in my schema, while accepting that value as a variable.
Minimal graphql.schema and models to reproduce
See above
versions
-
go run github.com/99designs/gqlgen version
? v0.17.36 -
go version
? go version go1.21.0 darwin/arm64