Last active
November 14, 2019 17:30
-
-
Save JosiasSena/0374df63512974da5cd9ec9b2869c5c9 to your computer and use it in GitHub Desktop.
Gists for https://medium.com/@josiassena/graphql-websocket-subscriptions-on-android-using-apollo-7e7311afdfca
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApolloSubscriptionClientFactory { | |
fun createSubscriptionApolloClient(sharedOkHttpClientBuilder: OkHttpClient.Builder): ApolloClient { | |
val okHttpClient = sharedOkHttpClientBuilder | |
.pingInterval(KEEP_ALIVE_INTERVAL, TimeUnit.SECONDS) | |
.build() | |
val subscriptionTransportFactory = WebSocketSubscriptionTransport.Factory("wss://your_subscription_host/graphql", okHttpClient) | |
return ApolloClient.builder() | |
.serverUrl("https://your_host_url/graphql") | |
.okHttpClient(okHttpClient) | |
.subscriptionConnectionParams(HeadersProvider.HEADERS) | |
.subscriptionTransportFactory(subscriptionTransportFactory) | |
.build() | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment