-
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
Update gqlgen init template to default to spec-compliant Int #3409
Update gqlgen init template to default to spec-compliant Int #3409
Conversation
…oncept to codegen
…ause the result model to also use an int marshaler / unmarshaler incorrectly...
…testserver gen files more closely
So I'm looking for the GitHub review "honk and throw money" button, but having trouble finding it. This is great! The Being lax in accepting While it is less harsh, it is also maybe less straightforward and getting errors only on send but not receive could make it harder to figure out what is happening. I don't feel strongly, and the fact that it is opt-in is nice. It's also not a ton of extra code to maintain. |
@phughes-scwx Hey, sorry for merging this if you already worked on the comment tweaks. I noticed that there's another large PR that has some conflicts with this one, and I wanted to get this in before that one. I hugely appreciate you doing the yeoman work of updating our docs and getting us closer to spec compliance! Are you able to make some parallel safecast tweaks to https://github.com/99designs/gqlgen/blob/master/graphql/uint.go ? |
Uh no problem. I'll add your suggested tweaks and the uint cast in a follow up. |
Partial solution to #3214.*
As described in the GraphQL spec, pretty clearly, the built in
Int
type must be a 32-bit integer:Our solution is not to enforce compliance, but instead default to a compliant setup in the
gqlgen init
configuration, and to support approaching schemas in a compliant way with the introduction of a newInt64
scalar.This PR includes the following updates:
Int64
.I have:
A more complete solution I envisioned would include another piece of configuration:
The concept here is that most Go APIs communicate via the
int
type, and it will be an annoyance to users to have resolvers and models all default toint32
all the time. This annoyance is important for data that the GraphQL API produces: users should ensure that the data they send conforms to the spec, and useint32
specifically. It also tells them to not use theInt
scalar for communicating integers that might overflow 32-bits: instead they can simply use theInt64
(or some other "BigInt") scalar.However, there is no need for us to enforce this part of the spec on data we consume. So, to be nice to the user (and keep them from just binding
Int
tographql.Int
as a quick and dirty fix), I think it would be best to allow them to bindInt
tographql.Int
(or anotherint
-communicating model) for input model fields and resolver arguments while usinggraphql.Int32
(or another) for objects, interfaces, enums, resolver result values, etc.In this solution, the default init template for
gqlgen.yaml
would be:This setup could be called "compliant config" as opposed to "strict compliant" / "non-compliant" configs.