apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.89k stars 728 forks source link

The operation couldn’t be completed. (OSStatus error -9847.) #3339

Closed BraveEvidence closed 8 months ago

BraveEvidence commented 9 months ago

Summary

I am trying to use Subscription on iOS simulator and I get error saying The operation couldn’t be completed. (OSStatus error -9847.)

Version

1.9.0

Steps to reproduce the behavior

https://github.com/BraveEvidence/iossubscription

Logs

The operation couldn’t be completed. (OSStatus error -9847.)

Anything else?

Is this a simulator issue? I don't have a real device to test on. I tried checking on https://www.osstatus.com and the error name is errSSLRecordOverflow

calvincestari commented 9 months ago

Hi @BraveEvidence - try using the ws protocol instead of wss for the websocket server address. It's unlikely your local host is serving WebSocket Secure which would be like using https locally.

BraveEvidence commented 9 months ago

Thank you @calvincestari for your reply. I tried changing the protocol to ws and now I get error saying "The operation couldn’t be completed. (ApolloWebSocket.WebSocket.WSError error 1.)"

Any suggestions

calvincestari commented 9 months ago

Check that you're using the correct GraphQL WebSocket subprotocol for your server.

BraveEvidence commented 9 months ago

@calvincestari I am using graphql-ws protocol. The subscriptions works fine on Android with Apollo Kotlin

calvincestari commented 9 months ago

You still need to make sure you're selecting the correct protocol when initializing the websocket. If you're already doing that then you'll need to do some more debugging on your side to determine what else could be wrong; is there anything else in the logs besides the WSError?

BraveEvidence commented 9 months ago

No other logs

calvincestari commented 9 months ago

If you can replicate this in a sample client then I can try with a websocket service locally to see if anything else if incorrect in the client. It's difficult to debug from that single error response.

BraveEvidence commented 9 months ago

Can you check my sample repo over here

calvincestari commented 9 months ago

I just took a look at the project now and I think you are using the wrong websocket subprotocol. In the Network.swift file you're using the .graphql_ws protocol. Note that the initializer requires you to specify the name of the subprotocol and not the name of the library.

I am using graphql-ws protocol. The subscriptions works fine on Android with Apollo Kotlin

graphql-ws is the name of the library but the protocol that it uses is graphql-transport-ws. You can see this in the first line of the Communication heading in that protocol document you linked to.

The WebSocket sub-protocol for this specification is: graphql-transport-ws.

This is confusing because the two packages have terrible library names that are too similar to the subprotocol names. The WSProtocol enum in the Apollo iOS documentation has details about which is supported by which library.

Change the subprotocol in the Network.swift file to .graphql_transport_ws and I think it should work for you.

BraveEvidence commented 8 months ago

@calvincestari Thank you for all the help

github-actions[bot] commented 8 months ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.