-
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
Support pointers in un/marshal functions #1277
Conversation
This branch has been running 99designs production workloads without issue so I'm inclined to merge it. |
I hate to break it to you but I think this is going to break the prisma guys, judging from the issue that came up last time I tried to remove it 😂 |
Bummer 😅 Oh well, after cleaning up my codegen changes it was easy enough to re-instate (I think) |
codegen/config/binder.go
Outdated
@@ -167,6 +167,7 @@ type TypeReference struct { | |||
Definition *ast.Definition | |||
GQL *ast.Type | |||
GO types.Type | |||
Target types.Type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we leave a comment that tries to explain the difference between Go and Type?
The target is the type of the physical field in the struct, and GO is the derived type when you combine it with the pointeryness required by the ast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - it's not even that, it's the difference between how to bind to the type, and how to traverse to the type from a field on another type, where sometimes that is due to gql AST requirements.
I wonder if there's an abstraction that represents both pointer juggling and casting sorta like “x is satisfiable by y if i do a, b and c”
🤔
codegen/config/binder.go
Outdated
ref.GO = obj.Type() | ||
ref.IsMarshaler = true | ||
default: | ||
} else if underlying := basicUnderlying(obj.Type()); def.IsLeafType() && underlying != nil && underlying.Kind() == types.String { | ||
// Special case for named types wrapping strings. Used by default enum implementations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I wonder if this needs a link to the issue, so that we dont almost delete it again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. TBH I'd still like to remove this case before 1.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suh-weet.
The generated code looks saner. Little more in the template, but it's pretty mechanical now.
c56848e
to
86c9ea4
Compare
This reverts commit 8996066.
86c9ea4
to
997efd0
Compare
Support pointers in un/marshal functions
Background
When updating protobuf to new v2 API we started to see a bunch of linting errors like:
We use custom scalars for third party types to bind protobuf timestamps, upon updating the un/marshal functions to act on pointers, I ran into the issue outlined in #1259.
Currently gqlgen assumes that all concrete binding can happen against value types and pointers will delegate through to the underlying value type.
This PR
Updates binding code to bind to support binding to pointers directly, supporting binding between pointers and values in both directions.
Fixes: #1259
I have: