I am trying to use GraphQL Subscription
on iOS simulator and I get error saying The operation couldn’t be completed. (OSStatus error -9847.)
I am using Apollo iOS 1.9.0
Is this a simulator issue? I don’t have a real device to test on
Here is my code
import Apollo
import Foundation
import ApolloWebSocket
class Network {
static let shared = Network()
private(set) lazy var apollo: ApolloClient = {
let client = URLSessionClient()
let cache = InMemoryNormalizedCache()
let store = ApolloStore(cache: cache)
let url = URL(string: "http://localhost:4000/graphql")!
let transport = RequestChainNetworkTransport(interceptorProvider: DefaultInterceptorProvider(client: client, shouldInvalidateClientOnDeinit: true, store: store), endpointURL: url)
my ViewController is as follows
import UIKit
import Apollo
import MyUserAPI
class ViewController: UIViewController {
var activeSubscription: Cancellable?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
startSubscription()
}
func startSubscription() {
activeSubscription = Network.shared.apollo.subscribe(subscription: MyUserSubscription()) { [weak self] result in
guard self != nil else {
return
}
switch result {
case .success(let graphQLResult):
if let user = graphQLResult.data?.newUser {
debugPrint(user.name)
}
if let errors = graphQLResult.errors {
debugPrint(errors[0].message ?? "Error")
}
case .failure(let error):
debugPrint(error.localizedDescription)
}
}
}
}
let webSocket = WebSocket(
url: URL(string: "wss://localhost:4000/graphql")!,
protocol: .graphql_ws
)
let webSocketTransport = WebSocketTransport(websocket: webSocket)
let splitTransport = SplitNetworkTransport(
uploadingNetworkTransport: transport,
webSocketNetworkTransport: webSocketTransport
)
return ApolloClient(networkTransport: splitTransport, store: store)
}()
}
Here is the complete repo