protobuf-ts icon indicating copy to clipboard operation
protobuf-ts copied to clipboard

Move interceptors from generated code into the transport layer

Open timostamm opened this issue 3 years ago • 3 comments

gRPC clients via @grpc/grpc-js bring their own interceptors. Letting the user choose from multiple interceptor mechanisms available seems overcomplicated.

This could be solved by moving interceptors to the transport layer.

timostamm avatar Jun 21 '21 10:06 timostamm

@timostamm Do you plan to deprecate the existing interceptor interface and nudge users to switch to the native mechanism or just move it around?

P.S. I'm asking because I'm currently working on some interceptors for my company that conform to RpcInterceptor interface.

be9 avatar Dec 07 '21 06:12 be9

The gRPC-web and Twirp transports use the fetch API without additional abstractions, so there is no native mechanism to switch to. The idea here is to keep RpcInterceptor as is, and just move the point where it is applied from the generated client to the transport.

    /**
     * MakeHat produces a hat of mysterious, randomly-selected color!
     *
     * @generated from protobuf rpc: MakeHat(spec.haberdasher.Size) returns (spec.haberdasher.Hat);
     */
    makeHat(input: Size, options?: RpcOptions): UnaryCall<Size, Hat> {
        const method = this.methods[0], opt = this._transport.mergeOptions(options);
        return stackIntercept<Size, Hat>("unary", this._transport, method, opt, input);
    }

It's about the stackIntercept() call in the last line.

timostamm avatar Dec 07 '21 09:12 timostamm

@timostamm thanks for clarification! 🙏

be9 avatar Dec 07 '21 10:12 be9