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

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

Open
william-maio-techlabs opened this issue Oct 27, 2020 · 0 comments
Open

Comments

@william-maio-techlabs
Copy link

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!

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