-
Notifications
You must be signed in to change notification settings - Fork 345
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
Add support for generating service client implementations with JSON serialization #106
Conversation
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.
@isherman I think this looks great, had a few questions about option flag names / Rpc/JsonRpc.
Out of curiosity, what server-side would this end up talking to? ...Twirp but JSON instead of binary? I suppose it's somewhat agnostic given the Rpc
interface, but still curious so that I can best understand how this would be used.
@@ -248,6 +248,8 @@ protoc --plugin=node_modules/ts-proto/protoc-gen-ts_proto ./batching.proto -I. | |||
|
|||
- With `--ts_proto_opt=outputClientImpl=false`, the client implementations, i.e. `FooServiceClientImpl`, that implement the client-side (currently Twirp-only) RPC interfaces will not be output. | |||
|
|||
- With `--ts_proto_opt=outputJsonClientImpl=true`, an additional client implementation will be output for each service, i.e. `FooServiceJsonClientImpl`, that uses JSON serialization. Has no effect if `outputClientImpl=false`. |
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.
What do you think about doing something like outputClientImpl = false | true | twirp | json
? I.e. false is off, true is a legacy value that means twirp, and json would be your new code?
I'm kinda thinking that shops will generally have a single preferred client?
I dunno, maybe not I guess?
Maybe this is better.
Maybe outputJsonClient=true/false
? I might deprecate the existing outputClientImpl
and rename it to outputTwirpClient
...
describe('simple service', () => { | ||
it('can echo with protobuf serialization', async () => { | ||
const echoRpc = { | ||
request: (_service: string, _method: string, data: Uint8Array) => { |
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.
Ah sure, that makes sense. How about using jest.fn
s though so we can assert the right values are passed? I.e. expect(...).toBeCalledWith
?
request: (_service: string, _method: string, data: Uint8Array) => { | ||
return Promise.resolve(data); | ||
}, | ||
requestJson: (_service: string, _method: string, data: unknown) => { |
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 was initially confused by this Rpc
having to have both request
and requestJson
... kinda thinking we should just generate separate Rpc
interfaces, i.e. the current Rpc
stays as is and becomes BinaryRpc
and the new one would be a JsonRpc
?
} | ||
rpc = rpc.addFunction(generateRpcRequestFn({ ...options, outputJsonClientImpl: false })); | ||
if (options.outputJsonClientImpl) { | ||
rpc = rpc.addFunction(generateRpcRequestFn(options)); |
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.e. here maybe just make a new JsonRpc
that is separate from the existing Rpc
type...
Closing as stale, and in favor of the discussion about a more general approach happening here: #106 |
First pass at #7.
Doesn't include support for Batching yet. Any other features this interacts with that I should be aware of?
Thoughts on this approach?