When we had initially set up Apollo, we used just the network transport. But subscriptions is an advanced use case which needs more configuration. So we have to use ApolloWebSocket.
Now we need to update our
ApolloClient instance to point to the subscription server.
Network.kt and update the following:
+ private val GRAPHQL_WEBSOCKET_ENDPOINT: String = "wss://hasura.io/learn/graphql"apolloClient = ApolloClient.builder().serverUrl(GRAPHQL_ENDPOINT).okHttpClient(okHttpClient).normalizedCache(normalizedCacheFactory, cacheKeyResolver)+ .subscriptionTransportFactory(WebSocketSubscriptionTransport.Factory(GRAPHQL_WEBSOCKET_ENDPOINT, okHttpClient)).addCustomTypeAdapter(CustomType.TIMESTAMPTZ, dateCustomTypeAdapter).build()
Note that we have added a new
GRAPHQL_WEBSOCKET_ENDPOINT and hence all GraphQL subscription queries can go through a websocket connection.
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs