-
Notifications
You must be signed in to change notification settings - Fork 764
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
Interceptors implementation #766
Comments
great |
Here's a high level view of what we are working on - these are still heavily WIP so things might change. We are still working through some issues with integrating with the internal use case, but we felt that this is a good checkpoint to write a summary. In order to write your own gRPC-Web client interceptor, you will need to implement the following interface:
So this is an example of how this is all put together.
The overall idea is that - in order to write your own interceptor, first you have to implement the In the In order to use the interceptors, you add it to the service constructor like this:
Specifying the interceptor this way will work for both unary call and server streaming calls. We call it We understand that this proposal deviates from #558 in some pretty major ways. Part of the reason why we chose to do things this way, is again, trying to have a unified implementation for both the internal use case and the open source use case here. In the internal use case, we have some requirements and have done some work to re-define the API around We'd like to hear your feedback on this. We have a partial PR working right now and we are still working through some issues. So let us know what you think! |
I just want to give an update here that we are working on the Interceptors implementation and should have something relatively soon.
The overall design we are borrowing elements from #558 and have to take into consideration of our internal use cases as well so there might be some deviation from #558. One of the goals we have is to have a shared implementation of Interceptors both for our internal use case and the open source use case here. I am going to post some more details on the overall design, some examples here soon.
One of the challenges we faced while working on this, is that internally, our codebase is entirely written in Closure - so we can use directives like@interface
,@implements
to define the Interceptors interface. And generally the user app code which depends on our grpc-web closure library are compiled together with our grpc-web library. One of the issues we faced is that - since we attempt to define theInterceptor
class as an@interface
in Closure, all the methods got reduced away to something like.a
when we compile the library into the npm module using--compilation_level=ADVANCED_OPTIMIZATIONS
. There doesn't seem to be a good way for the open source use case here, to be able to write a custom interceptor while it@implements
theInterceptor
interface we want.One workaround we found so far is to relax compiling our npm module to be using--compilation_level=SIMPLE_OPTIMIZATIONS
instead. This will work - all our "interfaces" classes will survive the compilation, but the drawback is that theindex.js
file size of the module will increase significantly. We are not sure how much that will affect the final code size after using tools likewebpack
- we are still looking into that.This all kind of stems from the fact that Closure and CommonJS has a very different style of exporting a module and we are still trying to figure out what's the best way to workaround this@interface
issue while trying to maintain the same implementation both internally and externally (this will really keep us maintainers sane!).Good news: we figured out how to export interfaces while building the module with ADVANCED_OPTIMIZATIONS, using
@export
and externs.So stay tuned - I am going to be posting more development on this in this issue soon. Thanks.
The text was updated successfully, but these errors were encountered: