-
Notifications
You must be signed in to change notification settings - Fork 1
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
Proposal: alternative interface that's more aligned with current idioms #23
Comments
@seanami would be curious to hear your opinions on this. |
Nice! I like this as a way to make the code more idiomatic and also be able to have a more typical stateful client object that can preserve configuration across multiple requests. I do use the service level class objects right now in some of my client configuration, but only to get the name of the service as a string for generating react-query cache names, and that can easily be replaced with something else. I do highly suggest putting all of the request functions in per-service files. That will solve the potential dupe issue, and also allow those who want similar semantics as the existing implementation to do: |
Any thoughts on naming of the files? Given |
Can service names be duplicated between separate If no duplicates are allowed, or the duplicates get merged into one definition, then I think just |
Background
Currently the generated functions are exposed as static methods on a class. For example:
I don't know the original intent of this pattern, but you lose any benefits of having a Service instance that tracks state and you get typescript that's not very idiomatic.
Proposal
Introduce a flag
use_static_classes
which defaults to true for now. Whenuse_static_classes
is false, you simply get an exported function that maps to the method name:And then:
Problem : conflicting function names
The main downside I see in this approach is that there could be ambiguous function names in the case where a single proto file contains multiple services with the same method. This seems unlikely in my experience, but a possible fix could be to generate multiple TS files.
For example: consider
accounts.proto
containsAccountService
andAdminService
, both withcreateAccount
methods.We could generate:
accounts.pb.ts
→ all the message definitions.accountservice.gw.pb.ts
→ functions for callingAccountService
gateway endpointsadminservice.gw.pb.ts
→ functions for callingAdminService
gateway endpointsAdditional Variant
As well as exposing simple functions, we could also introduce a more classical
Client
. The client instance could be used to store request configuration:The text was updated successfully, but these errors were encountered: