Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

73
Views
Integrate Apollo subscriptions on iOS with Action Cable being used on the backend for websockets

I'm trying to make Apollo subscriptions on iOS work with a backend that is using Action Cable to implement websockets. I learned that the iOS app needs to send command, channel and channel id to the backend to make subscriptions work (see here). I have tried to use the function write func write(_ str: String, force forced: Bool = false, id: Int? = nil) in WebSocketTransport.swift on WebSocketTransport object when initializing instance of Apollo. Below you can see how I'm doing that.

        let userDefault = UserDefaults.standard
        var authPayloads = Dictionary<String, String> ()
        var authToken = ""
        if let token = userDefault.object(forKey: "token") {
            authToken = "\(token)"
            authPayloads.updateValue(authToken, forKey: "authorization")
        }
       let configuration = URLSessionConfiguration.default
       configuration.httpAdditionalHeaders = authPayloads

        let map: GraphQLMap = authPayloads
        let wsEndpointURL = URL(string: "ws://localhost:8080/subscriptions/\(authToken)")!
        let endpointURL = URL(string: "http://localhost:8080/api")!

        websocket = WebSocketTransport(request: URLRequest(url: wsEndpointURL), connectingPayload: map)
       var channelId = Int(arc4random_uniform(100000))
       websocket?.write(stringify(json: ["command":"subscribe", "identifier": stringify(json: ["channel":"channelName", "channelId": channelId])]))

        let splitNetworkTransport = SplitNetworkTransport(
            httpNetworkTransport: HTTPNetworkTransport(
                url: endpointURL,
                configuration: configuration
            ),
            webSocketNetworkTransport: websocket!
        )
        return ApolloClient(networkTransport: splitNetworkTransport)
    }()

However, the backend isn't seeing what I'm writing to the WebSocket Transport object in their logs and I'm not able to subscribe to that specific channel. Any idea how I can make use Apollo subscriptions on iOS if the backend is using Action Cable, and make the two work together?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The only solution for now is to use Swift-ActionCableClient to recieve streams, and use the mutations/queries from ApolloClient.

Unfortenatly! Apollo iOS doesn't know how to communicate with ActionCable channels, this issue is reported on Apollo-iOS Github Issue #634 & Your issue Github Issue #454

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!