3

我需要集成subscription到我的 iOS 应用程序中。subscription在. _ localhost_ graphiql我已经将我的后端部署在Heroku. 我正在使用apollo-server而不是hasura. 我subscriptions的不适用于 Heroku 提供的 url,但它在localhost. Queries和url都mutations可以正常工作。所以我试图从我的 iOS 客户端访问我的。我将基本网址保留为我的本地主机。查询和突变部分适用于我的 iOS 客户端,但我的部分不起作用。localhostHerokusubscriptionsubscription

我已经通过添加这个配置了我的 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)

我也尝试替换httpws如下

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用于我的订阅并替换为我的订阅localhostHerokuurl 时,我收到以下错误。

s

4

1 回答 1

1

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

于 2020-06-18T13:19:02.527 回答