3

I need to integrate subscription in my Android app. The subscription works fine on localhost in graphiql. I have deployed my backend on Heroku. I am using apollo-server and not hasura. My subscriptions are not working for the url given by Heroku but it works fine on localhost. Queries and mutations work fine for both localhost and Heroku url. So I am trying to access my subscription from my Android client. I have kept the base url as my local host. I have configured my Android emulator correctly for localhost and the queries and mutations part works for my Android client but my subscription part is not working.

I have configured my Apollo client for subscription by adding this

.subscriptionTransportFactory(WebSocketSubscriptionTransport.Factory(baseUrl,okHttpClient))

My subscription code looks as follows

val healthConsultationSubscriptionList = GetHealthConsultationSubscription.builder().build()
        apolloClient.subscribe(healthConsultationSubscriptionList).execute(object :
            ApolloSubscriptionCall.Callback<GetHealthConsultationSubscription.Data> {
            override fun onFailure(e: ApolloException) {
                Log.i("datafailure","${e.message} ${e.localizedMessage} ${e.cause}" )
            }

            override fun onResponse(response: Response<GetHealthConsultationSubscription.Data>) {
                Log.i("datais", response.data()?.healthConsultation()?.chiefComplaint().toString() )
            }

            override fun onConnected() {
                Log.i("dataconnected","Connected")
            }

            override fun onTerminated() {
                Log.i("dataterminated","Terminated")
            }

            override fun onCompleted() {
                Log.i("datacompleted","Completed")
            }

        })

But I keep getting an error saying Subscription failed Subscription failed java.net.ProtocolException: Expected HTTP 101 response but was '400 Bad Request'

Also when I use Graphiql for my subscription and replace localhost with the Heroku url for my subscription , I get following error.

enter image description here

Are these two issues which I am facing are related to one another?

4

1 回答 1

1

所以我的代码没有问题。Heroku问题在于我正在使用的免费层。Hasura's我尝试用Subscription https://hasura.io/learn/graphql/android/subscriptions/1-subscription/替换我的订阅并且它有效。

于 2020-06-19T02:35:14.797 回答