I'm trying to implement a subscription using apollo client on iOS and I've looked into this thread but it doesn't work for me. I'm still getting this Authentication hook unauthorized this request, code: 1000
or Operation couldn't be completed Starscream.WSError error 1
My code is:
let apollo: ApolloClient = {
let authPayload = ["X-Hasura-Access-Key": "<my_key>",
"Content-Type": "application/json"]
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = authPayload
let map: GraphQLMap = authPayload
let url = URL(string: "https://url")!
let wsUrl = URL(string: "wss://url")!
let httpNetworkTransport = HTTPNetworkTransport(url: url, configuration: configuration)
let wsNetworkTransport = WebSocketTransport(request: URLRequest(url: wsUrl), connectingPayload: map)
return ApolloClient(networkTransport: SplitNetworkTransport(httpNetworkTransport: httpNetworkTransport,
webSocketNetworkTransport: wsNetworkTransport))
}()
It's working fine with queries though, but not with websocket and subscriptions. What am I doing wrong?
UPD: It's interesting, but if I remove the payload in the wsNetworkTransport, the error stays the same. Also if I add the request headers manually through request.addValue
, the error again the same.
I'm calling the client like so:
apollo.subscribe(subscription: OrdersSubscription(id: "123")) { (result, error) in
error == nil ? print(result!) : print(error!)
}
Is there any additional setup I'm missing? This thing really lack the docs.