我需要集成subscription
到我的 iOS 应用程序中。subscription
在. _ localhost
_ graphiql
我已经将我的后端部署在Heroku
. 我正在使用apollo-server
而不是hasura
. 我subscriptions
的不适用于 Heroku 提供的 url,但它在localhost
. Queries
和url都mutations
可以正常工作。所以我试图从我的 iOS 客户端访问我的。我将基本网址保留为我的本地主机。查询和突变部分适用于我的 iOS 客户端,但我的部分不起作用。localhost
Heroku
subscription
subscription
我已经通过添加这个配置了我的 Apollo 客户端以进行订阅
let httpNetworkTransport = HTTPNetworkTransport(url: URL(string: "http://localhost:5000")!)
httpNetworkTransport.delegate = self
let webSocketTransport = WebSocketTransport(request: URLRequest(url: URL(string: "http://localhost:5000")!))
let splitNetworkTransport = SplitNetworkTransport(
httpNetworkTransport: httpNetworkTransport,
webSocketNetworkTransport: webSocketTransport
)
return ApolloClient(networkTransport: splitNetworkTransport)
我也尝试替换http
为ws
如下
let webSocketTransport = WebSocketTransport(request: URLRequest(url: URL(string: "ws://localhost:5000")!))
订阅代码如下
subscription = Network.shared.apollo.subscribe(subscription: GetHealthConsultationSubscriptionSubscription()){
[weak self] result in
guard let self = self else {
return
}
switch result {
case .success(let result):
debugPrint(result.data?.healthConsultation.chiefComplaint)
case .failure(let error):
debugPrint(" Subscription Failure Error \(error)")
}
}
但我从我的 iOS 客户端收到如下错误
" Subscription Failure Error WSError(type: Starscream.ErrorType.upgradeError, message: \"Invalid HTTP upgrade\", code: 400)"
此外,当我Graphiql
用于我的订阅并替换为我的订阅localhost
的Heroku
url 时,我收到以下错误。