我有一个 iOS 项目,我正在使用 graphQL,Apollo/Starscream 用于服务/websockets。我没有查询和突变的问题,但订阅是个地狱。我订阅了一个聊天并建立了连接,但是当收到一条新消息时,它会抛出错误: 无法完成操作。(Starscream.HTTPUpgradeError 错误 0。)
如果我只是建立连接,一段时间后它会抛出以下内容:[connection] nw_socket_handle_socket_event [C1.1:1] Socket SO_ERROR [54: Connection reset by peer]
客户端订阅的代码是:
let magicToken = "Bearer provisionaltoken"
private lazy var webSocketTransport: WebSocketTransport = {
let url = URL(string: "wss://socketurl")!
let request = URLRequest(url: url)
let authPayload = ["Authorization": magicToken]
let map: GraphQLMap = authPayload
return WebSocketTransport(request: request, connectingPayload: map)
}()
private lazy var normalTransport: RequestChainNetworkTransport = {
let url = URL(string: "https://graphiqlurl")!
let client = URLSessionClient()
let provider = NetworkInterceptorProvider(client: client, store: store)
return RequestChainNetworkTransport(interceptorProvider: provider, endpointURL: url)
}()
private lazy var splitNetworkTransport = SplitNetworkTransport(
uploadingNetworkTransport: normalTransport,
webSocketNetworkTransport: webSocketTransport
)
private(set) lazy var apollo = ApolloClient(networkTransport: splitNetworkTransport, store: store)
private lazy var store = ApolloStore()
(网址和令牌是假的)
是不是有什么不妥?