let http_endpoint = URL(string: "http://localhost:8080/graphql")!
let ws_endpoint = URL(string: "ws://127.0.0.1:4000/graphql")!
let config = GraphQLWebSocketConfiguration()
config.behaviour = .lazy(closeTimeout: 60)
let ws = GraphQLWebSocket(
request: URLRequest(url: ws_endpoint),
config: config
)
let client = SwiftGraphQLClient.Client(
request: URLRequest(url: http_endpoint),
exchanges: [
FetchExchange(),
WebSocketExchange(client: socket)
]
)
let args = ExecutionArgs(
query: """
subscription Counter {
count(from: 10, to: 1)
}
""",
variables: [:]
)
client.subscribe(args)
.sink { completion in
print(completion)
} receiveValue: { result in
print(result)
}