I’m making an attempt to make use of GraphQL Subscription
on iOS simulator and I get error saying The operation couldn’t be accomplished. (OSStatus error -9847.)
I’m utilizing Apollo iOS 1.9.0
Is that this a simulator difficulty? I haven’t got an actual machine to check on
Right here is my code
import Apollo
import Basis
import ApolloWebSocket
class Community {
static let shared = Community()
non-public(set) lazy var apollo: ApolloClient = {
let shopper = URLSessionClient()
let cache = InMemoryNormalizedCache()
let retailer = ApolloStore(cache: cache)
// let supplier = NetworkInterceptorProvider(shopper: shopper, retailer: retailer)
let url = URL(string: "http://localhost:4000/graphql")!
let transport = RequestChainNetworkTransport(interceptorProvider: DefaultInterceptorProvider(shopper: shopper, shouldInvalidateClientOnDeinit: true, retailer: retailer), endpointURL: url)
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, retailer: retailer)
}()
}
Any my ViewController
is as follows
import UIKit
import Apollo
import MyUserAPI
class ViewController: UIViewController {
var activeSubscription: Cancellable?
override func viewDidLoad() {
tremendous.viewDidLoad()
// Do any extra setup after loading the view.
startSubscription()
}
func startSubscription() {
activeSubscription = Community.shared.apollo.subscribe(subscription: MyUserSubscription()) { [weak self] lead to
guard self != nil else {
return
}
swap outcome {
case .success(let graphQLResult):
if let person = graphQLResult.knowledge?.newUser {
debugPrint(person.identify)
}
if let errors = graphQLResult.errors {
debugPrint(errors[0].message ?? "Error")
}
case .failure(let error):
debugPrint(error.localizedDescription)
}
}
}
}
Right here is the entire repo