Apollo GraphQL with Vertx Subscription failed

466 Views Asked by At

I'm running Hasura GraphQL on docker instance(window machine) exposed at

http://192.168.99.100:8080/v1/graphql

I want to perform subscription in my verticle but getting the following exception:

    com.apollographql.apollo.exception.ApolloNetworkException: Subscription failed
        at com.apollographql.apollo.internal.RealApolloSubscriptionCall$SubscriptionManagerCallback.onNetworkError(RealApolloSubscriptionCall.java:246)
        at com.apollographql.apollo.internal.subscription.RealSubscriptionManager$SubscriptionRecord.notifyOnNetworkError(RealSubscriptionManager.java:524)
        at com.apollographql.apollo.internal.subscription.RealSubscriptionManager.onTransportFailure(RealSubscriptionManager.java:296)
        at com.apollographql.apollo.internal.subscription.RealSubscriptionManager$SubscriptionTransportCallback$2.run(RealSubscriptionManager.java:556)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
        at java.net.SocketInputStream.read(SocketInputStream.java:170)
        at java.net.SocketInputStream.read(SocketInputStream.java:141)

Here's my sample code for apollo graphQL client:

public class MyFirstVerticle extends AbstractVerticle {

    @Override
    public void start(Future<Void> fut) {

        OkHttpClient okHttp = new OkHttpClient().newBuilder().build();

        ApolloClient subscribe = ApolloClient.builder()
                .serverUrl("http://192.168.99.100:8080/v1/graphql")
                .subscriptionTransportFactory(new WebSocketSubscriptionTransport.Factory(
                        "wss://192.168.99.100:8080/v1/graphql", okHttp))
                .build();

        subscribe.subscribe(new MySubscription(1)).execute(new ApolloSubscriptionCall.Callback<Optional<MySubscription.Data>>() {
    ..... 
....
1

There are 1 best solutions below

1
user3154785 On

I found the solution, apparently it has to do with the type of connection you make. Im not an expert of this but, have you tried change wss to http?

:-)