I am using Apollo Android Client to execute Query/Mutation/Subscription Functionality in GraphQL. I am able to use Subscription functionality fine, However i need detailed information about various configurations exposed for Subscription Functionality like how to specify the time out.
Please do share any document or any sample test-case where all the configurations for Subscription Functionality are exposed.
Thanks for your Help!!
In terms of configuration (source), you can provide:
- the WebSocket engine to use (by default will be OkHttp)
- the WebSocket protocol to use (by default will be
- HTTP headers used at connection time
- an idle timeout after which the WebSocket will close if there is no network activity
- a reopen policy to use when a network error happens
Other than that, the documentation about subscriptions is available here, authentication here and error handling here.
Don’t hesitate to let us know if you have further questions about this.
Hi @Benoit_Lubek , so i am using the Apollo Android Client and here is how i create the subscription
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(
apolloClientBuilder.subscriptionTransportFactory(new WebSocketSubscriptionTransport.Factory("https://apollo-fullstack-tutorial.herokuapp.com/graphql", okHttpClient));
Does that mean when i create the subscription using the above settings, the subscription functionality will work for 1 minute and websocket will timeout after 1 minute?
As per the documentation here ApolloClient.Builder (apollo-runtime 1.2.2 API)
it looks like it says Timeout for how long subscription manager should wait for a keep-alive message from the subscription server before reconnect.
i.e it will reconnect after this timeout. So does that mean that Subscriptions would automatically reconnect after timeouts?
Please let me know about it?
Thanks in Advance!!
That’s correct. As a side note, are you really using version 1? It is quite old, I would recommend to try the latest 3.x if you can do Kotlin, otherwise, the latest 2.x.
@Benoit_Lubek : Yes We are using version 2.5.11 , we have a constraint to do it in Java only and we did pick it up based on the suggestions in the forum only. With respect to Subscription, we have observed that after time out it doesn’t reconnect, Can this be due to the servers ability to send heartbeats? I will cross verify the scenarios once and then get back on this.
Hi @Benoit_Lubek , Is there a default disconnect in Subscription? We tried simulating the Subscription(TripsBooked) using above settings on Heroku Server(wss://apollo-fullstack-tutorial.herokuapp.com/graphql) and observed that the subscriptions gets disconnected after an hour. Is there some default settings?
There is no automatic disconnection on the client side. Maybe the server disconnects however.
On your side I would recommend to manually retry subscribing when receiving an
onFailure in your
ApolloSubscriptionCall.Callback (you can implement an exponential backoff, and maybe a maximum number of retries). This will reconnect the websocket.