Autobind Getter and Haser for Protobuf RPC#3980
Conversation
|
@raphaelfff Hey thanks! It looks like there are some minor lint nits and you might need to run |
|
@StevenACoffman i think its all there! |
There was a problem hiding this comment.
Wonder what happen here, why did the types swap?
This might not be related to your PR, but its something we may want to look into.
There was a problem hiding this comment.
Yup, unrelated to my changes, seems like a codegen order instability, shouldnt hold this PR tho!
There was a problem hiding this comment.
If the codegen is unstable, it seems likely that the source of that instability is fairly recent, if it is not caused by this PR.
If it is unrelated to these changes, I would think we would have been seeing intermittent failures if it were a long-standing issue.
When I look through the commits to master: https://github.com/99designs/gqlgen/commits/master/
I do not see any failures like that (other than those that were cancelled because I impatiently merged another PR before they finished)
There was a problem hiding this comment.
I honestly cannot see how this PR would interfere with type creation... but maybe you can shed some light on it :)
There was a problem hiding this comment.
Okay i tuned the tpl to not add a new line, this reduces the diff, it also removed that instability... not sure why/how...
There was a problem hiding this comment.
Yeah, I agree it is weird. I'm not going to pursue it until it comes back, but it might be a sign that there's something lurking we are just barely avoiding?
There was a problem hiding this comment.
I vote that there is something hiding there :)
| google.golang.org/protobuf v1.36.11 | ||
| ) | ||
|
|
||
| require golang.org/x/sync v0.19.0 // indirect |
There was a problem hiding this comment.
This seems sort of odd as well.
There was a problem hiding this comment.
go mod tidy did that 🤷
There was a problem hiding this comment.
go version go1.25.0 darwin/arm64
There was a problem hiding this comment.
🤷 then such is as the gods decree, and not for mere mortals such as I to question.
|
@StevenACoffman can we get another CI run ? |
|
@StevenACoffman comments adressed and build is green |
|
Thanks! |
|
How's a merge looking ? |
|
I think the docs were not updated. |
|
@ikonst Can you make a PR for this? |
|
I can try :) I was obviously trying to understand it myself by going to the docs, but I can pit Gemini against it it: Does this description seem right? If so, I can make a PR based on that (obviously less verbose...). |
|
BTW, Protobuf Editions became generally available with the release of protoc 27.0. In protobuf, the concept of a Field's "presence" is whether that field has a value. Fields are defined as having either: implicit presence, where the generated message API stores field values (only), and explicit presence, where the API also stores whether or not a field has been set. When a Field has explicit presence, you need In protobuf editions, you can specify explicit default values for singular non-message fields. For example, let’s say you want to provide a default value of 10 for the If the sender does not specify
If the sender does send a value for Explicit default values cannot be specified for fields that have the Gemini generated summary follows: The autoBindGetterHaser flag is a configuration option added in gqlgen (specifically introduced in PR #3980) to improve compatibility with Protobuf (gRPC) generated Go structs. Here is the explanation you can use for your documentation: What does autoBindGetterHaser do?
Rationale: Why was this added?The primary driver for this feature is support for Protobuf (gRPC). Protobuf Access Pattern: Modern Go code generated by protoc-gen-go (Protobuf) encapsulates fields to handle nullability and default values safely. Instead of accessing fields directly (which might be nil pointers or unexported), the standard pattern is to use the generated accessor methods: GetEmail() returns the string value (safely handling nil). HasEmail() returns a boolean indicating whether the field was set (important for distinguishing between an "empty string" and "null"). Removing Boilerplate: Before this flag, if you wanted to use a generated Protobuf struct as a gqlgen model, you often had to write custom resolvers for every field just to call these methods, or create wrapper structs. gqlgen's default binder would fail to find the data if the fields were unexported or if it didn't know how to check "presence" correctly. Seamless Integration: By enabling autoBindGetterHaser, you can map your GraphQL schema directly to your Protobuf-generated Go structs. gqlgen will "do the right thing" by calling the generated Get and Has methods automatically. Usage Example in Schema: |
With this PR autobind now supports binding to RPC editions generated structs
I have: