-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Gqlgen not compliant with graphql spec for Int type #3214
Comments
@roeest does updating the models:
# ...
Int:
model:
- github.com/99designs/gqlgen/graphql.Int32 Make the server spec-compliant, as you see it? |
For a greenfield schema this would work, but with some caveats. Mapping The problem is with existing schemas. Making your schema spec compliant results in a breaking change to the api, no matter how you spin it. Returning 32 bit values in apis that returned 64 bit values will truncate the result. Similarly inputs that use 64bit values can error out when being unmarshaled which is also a breaking change. Changing the type of a specific field to a I don't know what the best path forward is here, but gqlgen should at least implement some preventative measures to ensure users aren't shooting themselves in the foot when it comes to spec compliance. |
I am trying to imagine a PR to introduce this here, and what I come up with is one that changes the init behavior and documentation... Including documentation that would specifically point out using Int64 / BigInt scalars. I think existing schemas are SOL on this: using int32 across the resolver interface is pretty much the best / only way to ensure implementors take this into consideration. Are there any updates that you think should / must be made to either the scalar (Int, Int32, Int64) implementations or the codegen / graphql package to ensure we error correctly? I'm imagining adding a safecast step to Int32 Marshal / Unmarshal... but I feel like I'm missing something maybe. |
Ah I think I see now: we should have the graphql I think that, in the context of the suggested change to the default yaml setup, we can say that it's not really important to have the inputs map to This is a pretty drastic change: I think maybe introducing a configuration setting in the yaml to do this and then advocating for that to become the default as well may be the best route to take... |
I think the current marshal/unmarshal methods would work correctly as is, it's more about making sure that the right ones are being used by the mappings in the configuration. I was playing around with a CI step that parsed the configuration and made sure that the mapping for Built in Int64 scalar support would be nice, similarly to other built in scalars ( |
OK, this above PR actually solves the issue, but is pretty strict. I failed at my attempt to introduce a "partial compliance" mode to the config that allows |
What happened?
Gqlgen treats the
Int
graphql type as a golang 64 bit integer. The graphql spec states that theInt
graphql type represents a 32 bit integer. This causes issues with clients that assume the underlying type of an integer is 32 bits either by overflowing them or by making them error out altogether.What did you expect?
Behavior that matches the graphql spec
Int
input that overflows 32bit integersInt
results that overflow or even better return an indicative errorMinimal graphql.schema and models to reproduce
Any schema with an
Int
in an input or a regular typeversions
go run github.com/99designs/gqlgen version
? v0.17.49go version
? go version go1.22.4 darwin/arm64The text was updated successfully, but these errors were encountered: