Skip to content

Why there is no abstract class for client? why expose $... methods? #942

@lesomnus

Description

@lesomnus

Assume a following proto:

service MerchantService {
	rpc Search(MerchantSearchRequest) returns  (MerchantSearchResponse);
}

Current plugin generates following client code:

class MerchantServiceClient extends $grpc.Client {
  MerchantServiceClient($grpc.ClientChannel channel,
      {$grpc.CallOptions? options,
      $core.Iterable<$grpc.ClientInterceptor>? interceptors})
      : super(channel, options: options,
        interceptors: interceptors);

  $grpc.ResponseFuture<$0.MerchantSearchResponse> search($0.MerchantSearchRequest request, {$grpc.CallOptions? options}) {
    return $createUnaryCall(_$search, request, options: options);
  }
}

It defines a search method that is expected to be used by the users, but it also exposes methods from $grpc.Client that are not expected to be used by them.

How about to generate something like:

abstract class MerchantServiceClient {
  $grpc.ResponseFuture<$0.MerchantSearchResponse> search($0.MerchantSearchRequest request, {$grpc.CallOptions? options}) {
    return $createUnaryCall(_$search, request, options: options);
  }
}

class _MerchantServiceClient extends $grpc.Client implements MerchantServiceClient {
  MerchantServiceClient($grpc.ClientChannel channel,
      {$grpc.CallOptions? options,
      $core.Iterable<$grpc.ClientInterceptor>? interceptors})
      : super(channel, options: options,
        interceptors: interceptors);

  $grpc.ResponseFuture<$0.MerchantSearchResponse> search($0.MerchantSearchRequest request, {$grpc.CallOptions? options}) {
    return $createUnaryCall(_$search, request, options: options);
  }
}

MerchantServiceClient createMerchantServiceClient($grpc.ClientChannel channel,
    {$grpc.CallOptions? options,
    $core.Iterable<$grpc.ClientInterceptor>? interceptors}) {
  return MerchantServiceClient(channel,
      options: options, interceptors: interceptors);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions