google / rejoiner

Generates a unified GraphQL schema from gRPC microservices and other Protobuf sources
https://google.github.io/rejoiner/
Apache License 2.0
3.67k stars 140 forks source link

Request for Help on `GraphQL Stream (based on gRPC streaming)` #111

Open william-maio-techlabs opened 4 years ago

william-maio-techlabs commented 4 years ago

Hello, I am having issue implementing GraphQL Stream (based on gRPC streaming) with the following exception:

class graphql.GraphQLContext cannot be cast to class com.google.api.graphql.grpc.RejoinerStreamingContext (graphql.GraphQLContext and com.google.api.graphql.grpc.RejoinerStreamingContext are in unnamed module of loader 'app')
java.lang.ClassCastException: class graphql.GraphQLContext cannot be cast to class com.google.api.graphql.grpc.RejoinerStreamingContext (graphql.GraphQLContext and com.google.api.graphql.grpc.RejoinerStreamingContext are in unnamed module of loader 'app')

I am referencing: https://github.com/google/rejoiner/tree/master/examples-gradle/src/main/java/com/google/api/graphql/examples/streaming

I am working with the following type of proto: rpc SayHelloStreaming (HelloRequest) returns (stream Msg) {} as oppose to rpc SayHelloStreaming (HelloRequest) returns (stream HelloReply) {} referenced here: https://github.com/google/rejoiner/blob/master/examples-gradle/src/main/proto/helloworld_streaming.proto#L27

I was able to create a non-stream version:

  @Query("SayHelloNoStream")
  HelloReply sayHelloNoStream(
      HelloRequest request,
      StreamingGreeterGrpc.StreamingGreeterBlockingStub blockingStub) {
    var iterator = blockingStub.sayHello(request);
    var builder = HelloReply.newBuilder();
    while (iterator.hasNext()){
      Msg msg = iterator.next();
      builder.addMsg(msg);
    }
    return builder.build();
  }

But with the stream version, I am getting class graphql.GraphQLContext cannot be cast to class exception

  @Query("SayHelloWithStream")
  HelloReply sayHelloWithStream(
      HelloRequest request,
      StreamingGreeterGrpc.StreamingGreeterStub streamStub,
      DataFetchingEnvironment dataFetchingEnvironment) {
    StreamObserver<Msg> observer =
        new GraphQlStreamObserver<Msg, Msg>(dataFetchingEnvironment) {
          @Override
          protected Msg getData(Msg value, ListValue path) {
            return value;
          }
        };
    streamStub.sayHello(request, observer);
    return null;
  }

I am using rejoiner 0.3.1

Thank you!