grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
860 stars 271 forks source link

Is there an equivalent of Java's BlockingStub? #622

Open juskek opened 1 year ago

juskek commented 1 year ago
dart-grpc 3.1.0 I am trying to write a grpc client for TypeDB (a graph database), and am using protoc to compile TypeDB's [.proto definition files](https://github.com/vaticle/typedb-protocol) into Dart service and message definitions. When compiling to **Java**, the following service definition, `TypeDBBlockingStub extends AbstractStub`is generated: ```java // // Decompiled by Procyon v0.5.36 // package com.vaticle.typedb.protocol; import io.grpc.stub.ClientCalls; import io.grpc.CallOptions; import io.grpc.Channel; import io.grpc.stub.AbstractStub; public static final class TypeDBBlockingStub extends AbstractStub { private TypeDBBlockingStub(final Channel channel) { super(channel); } private TypeDBBlockingStub(final Channel channel, final CallOptions callOptions) { super(channel, callOptions); } protected TypeDBBlockingStub build(final Channel channel, final CallOptions callOptions) { return new TypeDBBlockingStub(channel, callOptions); } public CoreDatabaseProto.CoreDatabaseManager.Contains.Res databasesContains(final CoreDatabaseProto.CoreDatabaseManager.Contains.Req request) { return (CoreDatabaseProto.CoreDatabaseManager.Contains.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getDatabasesContainsMethod(), this.getCallOptions(), (Object)request); } public CoreDatabaseProto.CoreDatabaseManager.Create.Res databasesCreate(final CoreDatabaseProto.CoreDatabaseManager.Create.Req request) { return (CoreDatabaseProto.CoreDatabaseManager.Create.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getDatabasesCreateMethod(), this.getCallOptions(), (Object)request); } public CoreDatabaseProto.CoreDatabaseManager.All.Res databasesAll(final CoreDatabaseProto.CoreDatabaseManager.All.Req request) { return (CoreDatabaseProto.CoreDatabaseManager.All.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getDatabasesAllMethod(), this.getCallOptions(), (Object)request); } public CoreDatabaseProto.CoreDatabase.Schema.Res databaseSchema(final CoreDatabaseProto.CoreDatabase.Schema.Req request) { return (CoreDatabaseProto.CoreDatabase.Schema.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getDatabaseSchemaMethod(), this.getCallOptions(), (Object)request); } public CoreDatabaseProto.CoreDatabase.TypeSchema.Res databaseTypeSchema(final CoreDatabaseProto.CoreDatabase.TypeSchema.Req request) { return (CoreDatabaseProto.CoreDatabase.TypeSchema.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getDatabaseTypeSchemaMethod(), this.getCallOptions(), (Object)request); } public CoreDatabaseProto.CoreDatabase.RuleSchema.Res databaseRuleSchema(final CoreDatabaseProto.CoreDatabase.RuleSchema.Req request) { return (CoreDatabaseProto.CoreDatabase.RuleSchema.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getDatabaseRuleSchemaMethod(), this.getCallOptions(), (Object)request); } public CoreDatabaseProto.CoreDatabase.Delete.Res databaseDelete(final CoreDatabaseProto.CoreDatabase.Delete.Req request) { return (CoreDatabaseProto.CoreDatabase.Delete.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getDatabaseDeleteMethod(), this.getCallOptions(), (Object)request); } public SessionProto.Session.Open.Res sessionOpen(final SessionProto.Session.Open.Req request) { return (SessionProto.Session.Open.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getSessionOpenMethod(), this.getCallOptions(), (Object)request); } public SessionProto.Session.Close.Res sessionClose(final SessionProto.Session.Close.Req request) { return (SessionProto.Session.Close.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getSessionCloseMethod(), this.getCallOptions(), (Object)request); } public SessionProto.Session.Pulse.Res sessionPulse(final SessionProto.Session.Pulse.Req request) { return (SessionProto.Session.Pulse.Res)ClientCalls.blockingUnaryCall(this.getChannel(), TypeDBGrpc.getSessionPulseMethod(), this.getCallOptions(), (Object)request); } } ``` However, when compiling to **Dart** using `protoc --dart_out=grpc: `, `TypeDBBlockingStub extends AbstractStub` is not generated. I can see that [grpc-dart](https://pub.dev/documentation/grpc/latest/grpc/grpc-library.html) does not have `AbstractStub` unlike in [grpc-java](https://grpc.github.io/grpc-java/javadoc/). Is there an equivalent class I can use to implement TypeDBBlockingStub manually? ## Repro steps 1. Clone typedb-protocol repo for with proto definition files `git clone https://github.com/vaticle/typedb-protocol` 2. Ensure [dart protobuf compiler](https://pub.dev/packages/protoc_plugin) is installed : `dart pub global activate protoc_plugin`. 3. Cd into the typedb-protocol repo 4. Compile proto definition files into dart files in desired project directory: `protoc --dart_out=grpc:/lib/generated **/*.proto` Expected result: Find `TypeDBBlockingStub` class definition Actual result:`TypeDBBlockingStub` class definition does not exist