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

Add option that allows returning also response object from client calls.

Open Meyhem opened this issue 4 years ago • 1 comments

I noticed that when using option outputClientImpl=grpc-web the generated client calls return typed protobuf message as typescript type but prevents caller to access response metadata which might also be important to caller. Would it be possible to add option to generator that exposes response object to the caller ? Exposing response metadata can be helpful for example when server wants to return pagination info in response trailers.

Current generated client

export interface CategoryService {
  CreateCategory(
    request: DeepPartial<CreateCategoryRequest>,
    metadata?: grpc.Metadata
  ): Promise<CreateCategoryReply>; // <----- returns only Reply
}

Proposal

export interface CategoryService {
  CreateCategory(
    request: DeepPartial<CreateCategoryRequest>,
    metadata?: grpc.Metadata
  ): Promise<[CreateCategoryReply, grpc.UnaryOutput<any>]>; // <----- returns also response object
}

By using tuple, callers can easily extract response object via deconstruction

const [message, resp] = serviceClient.CreateCategory({...})

or simply ignore it

const [message] = serviceClient.CreateCategory({...})

Meyhem avatar Dec 17 '21 19:12 Meyhem

Personally I'd be tempted to cheat and assert/nudge the server to return pagination info in-band, instead of as metadata, but otherwise yet-another-option to generate this style of output sounds fine.

stephenh avatar Dec 18 '21 21:12 stephenh