99designs / 99designs/gqlgen

Gqlgen won't allow int values

Ouverte
#2,823 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Go
Étoiles
10.8k
Forks
1.3k
Merge moyen
2 j 36 min
PR mergées (30 j)
26

Description

### 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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.