【发布时间】:2020-09-26 04:31:31
【问题描述】:
我需要在我的 Android 应用程序中集成 subscription。 subscription 在localhost 在graphiql 上工作正常。我已经在 Heroku 上部署了我的后端。我使用的是apollo-server 而不是hasura。
我的subscriptions 不适用于Heroku 提供的网址,但它在localhost 上运行良好。 Queries 和 mutations 适用于 localhost 和 Heroku url。
所以我正在尝试从我的 Android 客户端访问我的订阅。我将基本网址保留为我的本地主机。我已经为localhost 正确配置了我的Android 模拟器,queries 和mutations 部分适用于我的Android 客户端,但我的订阅部分不起作用。
我已经通过添加这个为subscription 配置了我的Apollo 客户端
.subscriptionTransportFactory(WebSocketSubscriptionTransport.Factory(baseUrl,okHttpClient))
我的订阅代码如下所示
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")
}
})
但我一直收到错误消息说Subscription failed Subscription failed java.net.ProtocolException: Expected HTTP 101 response but was '400 Bad Request'
此外,当我使用 Graphiql 进行订阅并将 localhost 替换为我的订阅的 Heroku url 时,我收到以下错误。
我面临的这两个问题是否相互关联?
【问题讨论】:
标签: graphql apollo apollo-server graphql-subscriptions apollo-android