Skip to content
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

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

Open
lesomnus opened this issue Sep 22, 2024 · 0 comments
Open

Comments

@lesomnus
Copy link

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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant