'running subscription on django-channels-graphql-ws from kotlin apollo client shows "network error while executing subscription"

subscription works when tried from desktop client(AltairGraphql client).

chatSubscription(chatroom:"room"){
    message{
      id
      sender{
        username
      }
    }
  }
}

from kotlin gives error: "Network error while executing ChatSubscription"

val okHttpClient = OkHttpClient.Builder().addInterceptor(AuthorizationInterceptor(requireContext(), userToken!!))
    //.addNetworkInterceptor(NetworkInterceptor())
    .build()
val apolloClient = ApolloClient.Builder()
    .httpServerUrl("http://localhost:8000")
    .webSocketServerUrl("ws://localhost:8000/ws/graphql")
    .okHttpClient(okHttpClient)
    .build()
Timber.d("reealltime 3")

apolloClient.subscription(ChatSubscription("641fffb3-9e67-4a20-9fde-add14fbf136e"))
    .toFlow()
    .collect {
        Timber.d("reealltime ${it.data?.chatSubscription?.message?.text}")
        val adapter = binding.rvChatMessages.adapter as NewChatMessagesAdapter
        adapter.addMessage(it.data?.chatSubscription?.message)
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source