entproto: fix service.List pageToken for custom fields (UUID/string) #600
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The current List service template generates faulty code if a custom GoType field is used (currently only UUID and string types are supported by this fix).
I haven't tested this on a large set of inputs and probably I'm lacking context why the pageToken has been implemented this way (also why it is Base64-encoded), but using a call to the
field_to_ent
template hopefully leads to a more sane behavior, as it is also used forGet()
andUpdate()
templates.Example schema
Example 1: UUID type
Example 2: String type
Diff of rendered code
IDLTE
only accepts custom type (in this case pulid.PULID). Therefore the green lines are working code:Alternatives
It would probably be cleaner to allow implementing
UnmarshalProto
/MarshalProto
for custom types similar like we can implement a customUnmarshalGQL
/MarshalGQL
. The reasoning is that the Valuer/Scanner interface used by the database driver is not necessarily what we want to represent in the protobuf types.