-
Notifications
You must be signed in to change notification settings - Fork 349
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
fix: Fix generating wrong web-rpc implementation for wrapper-type method arg #978
fix: Fix generating wrong web-rpc implementation for wrapper-type method arg #978
Conversation
Hi @programmador ; this looks great! I'm kinda surprised, the build passed without any changes to our integration tests. Usually for PRs, we try to find an example/test project in our https://github.com/stephenh/ts-proto/tree/main/integration/grpc-web And then update the Basically, can you look through the We probably have some tests that are already returning wrapper types as response messages, but not request messages...but not sure. This will just ensure your fix doesn't accidentally regress if/when things are updated in the future. Thanks! |
While running
Should I undertake anything or just ignore them? |
O that's ok now, I just had to run few |
As I see grpc-web tests do not generate any TypeScript rpc definitions. I've added an rpc method which both receives and returns a StringValue wrapper. Then I've re-run commands specified by |
Anyway I've pushed my changes - please look whether it's what was required or not. |
@programmador this looks great! Can you go ahead and check in the generated code changes? Having those in the PR is a lot what our "tests" are. |
Sorry, it seems like the more we conversate the more I realize I do not understand. There is no generated code produced by grpc-web tests. The only generated thing is example.bin. So at changes of what do I have to look? Maybe the code is generated inside of tests and is not being saved anywhere so I have to dump something to stdout in test code? |
If You're asking about my project's code - so here's a contract: enum BlockType {
BLOCK_TYPE_NONE = 0;
BLOCK_TYPE_LITE = 1;
BLOCK_TYPE_FULL = 2;
}
message BlockPrediction {
BlockType type = 1;
}
...
service RiskService {
...
rpc PredictBlock(google.protobuf.StringValue) returns (models.BlockPrediction) {};
}
Here's a generated code before fix (1.151.1): PredictBlock(request: DeepPartial<StringValue>, metadata?: grpc.Metadata): Observable<BlockPrediction> {
return this.rpc.unary(RiskServicePredictBlockDesc, string.fromPartial(request), metadata);
} And here's one after the fix: PredictBlock(request: DeepPartial<StringValue>, metadata?: grpc.Metadata): Observable<BlockPrediction> {
return this.rpc.unary(RiskServicePredictBlockDesc, StringValue.fromPartial(request), metadata);
} |
Older version of ts-proto (^1.93.2 though I don't know which exactly without ^ sign) generated even more strange code: PredictBlock(request: DeepPartial<StringValue>, metadata?: grpc.Metadata): Observable<BlockPrediction> {
return this.rpc.unary(RiskServicePredictBlockDesc, string | undefined.fromPartial(request), metadata);
} So we have 3 variants of substitution before
where the latest one is correct. |
Hi @programmador , sorry, I just meant the changes to the I went and pushed that commit to this PR, and it shows the changes to the output are:
Is that what you expect for the |
Fwiw I think ideally this code would end up being:
Or something like that, I forget what the StringValue.wrap/unwrap methods are/don't see them in the output at the moment, but then the user wouldn't even know about the Happy to leave that for another PR though, because it'd be a more complicated change. |
Yes, I thought about whether rpc signature should work just with scalar values. And realized that wrappers are currently supported in ts-proto at protobuf(lower) level but not at rpc(upper) level. So i decided not to go so far, at least not in this PR. And also when I'm not sure how it's meant to be. Though now I understand what we see it from the same angle. UPD: that other PR should also respect |
Exactly! But how did You make that change? By hand? I thought it should be generated automatically either when I run tests (I don't know how they should work here) or by running protoc scripts from yarn 'build:test' job. Tried both - and nothing generated the code. |
Ah yeah, sorry, I ran |
## [1.165.2](v1.165.1...v1.165.2) (2023-12-20) ### Bug Fixes * Fix generating wrong web-rpc implementation for wrapper-type method arg ([#978](#978)) ([063fd29](063fd29))
🎉 This PR is included in version 1.165.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixes #862
Though I didn't see any difference in generated wrapper related rpc definition code when switching between different useOptionals values.