Docs
Launch GraphOS Studio
You're viewing documentation for a previous version of this software. Switch to the latest stable version.


CLASS

WebSocketTransport

public class WebSocketTransport

A network transport that uses web sockets requests to send to a server.

Properties

delegate

public weak var delegate: WebSocketTransportDelegate?

clientName

public var clientName: String
  • NOTE: Setting this won't override immediately if the socket is still connected, only on reconnection.

clientVersion

public var clientVersion: String
  • NOTE: Setting this won't override immediately if the socket is still connected, only on reconnection.

Methods

init(websocket:store:clientName:clientVersion:sendOperationIdentifiers:reconnect:reconnectionInterval:allowSendingDuplicates:connectOnInit:connectingPayload:requestBodyCreator:operationMessageIdCreator:)

public init(websocket: WebSocketClient,
store: ApolloStore? = nil,
clientName: String = WebSocketTransport.defaultClientName,
clientVersion: String = WebSocketTransport.defaultClientVersion,
sendOperationIdentifiers: Bool = false,
reconnect: Bool = true,
reconnectionInterval: TimeInterval = 0.5,
allowSendingDuplicates: Bool = true,
connectOnInit: Bool = true,
connectingPayload: GraphQLMap? = [:],
requestBodyCreator: RequestBodyCreator = ApolloRequestBodyCreator(),
operationMessageIdCreator: OperationMessageIdCreator = ApolloSequencedOperationMessageIdCreator())

Designated initializer

  • Parameters:
    • websocket: The websocket client to use for creating a websocket connection.
    • store: [optional] The ApolloStore used as a local cache. Defaults to nil.
    • clientName: The client name to use for this client. Defaults to Self.defaultClientName
    • clientVersion: The client version to use for this client. Defaults to Self.defaultClientVersion.
    • sendIdentifiers: Whether or not to send operation identifiers with operations. Defaults to false.
    • reconnect: Whether to auto reconnect when websocket looses connection. Defaults to true.
    • reconnectionInterval: How long to wait before attempting to reconnect. Defaults to half a second.
    • allowSendingDuplicates: Allow sending duplicate messages. Important when reconnected. Defaults to true.
    • connectOnInit: Whether the websocket connects immediately on creation. If false, remember to call resumeWebSocketConnection() to connect. Defaults to true.
    • connectingPayload: [optional] The payload to send on connection. Defaults to an empty GraphQLMap.
    • requestBodyCreator: The RequestBodyCreator to use when serializing requests. Defaults to an ApolloRequestBodyCreator.
    • MessageIdCreator: The OperationMessageIdCreator used to generate a unique message identifier per request. Defaults to ApolloSequencedOperationMessageIdCreator.

Parameters

NameDescription
websocketThe websocket client to use for creating a websocket connection.
store[optional] The ApolloStore used as a local cache. Defaults to nil.
clientNameThe client name to use for this client. Defaults to Self.defaultClientName
clientVersionThe client version to use for this client. Defaults to Self.defaultClientVersion.
sendOperationIdentifiersWhether or not to send operation identifiers with operations. Defaults to false.
reconnectWhether to auto reconnect when websocket looses connection. Defaults to true.
reconnectionIntervalHow long to wait before attempting to reconnect. Defaults to half a second.
allowSendingDuplicatesAllow sending duplicate messages. Important when reconnected. Defaults to true.
connectOnInitWhether the websocket connects immediately on creation. If false, remember to call resumeWebSocketConnection() to connect. Defaults to true.
connectingPayload[optional] The payload to send on connection. Defaults to an empty GraphQLMap.
requestBodyCreatorThe RequestBodyCreator to use when serializing requests. Defaults to an ApolloRequestBodyCreator.
operationMessageIdCreatorThe OperationMessageIdCreator used to generate a unique message identifier per request. Defaults to ApolloSequencedOperationMessageIdCreator.

isConnected()

public func isConnected() -> Bool

ping(data:completionHandler:)

public func ping(data: Data, completionHandler: (() -> Void)? = nil)

initServer()

public func initServer()

closeConnection()

public func closeConnection()

deinit

deinit

unsubscribe(_:)

public func unsubscribe(_ subscriptionId: String)

updateHeaderValues(_:reconnectIfConnected:)

public func updateHeaderValues(_ values: [String: String?], reconnectIfConnected: Bool = true)

updateConnectingPayload(_:reconnectIfConnected:)

public func updateConnectingPayload(_ payload: GraphQLMap, reconnectIfConnected: Bool = true)

pauseWebSocketConnection()

public func pauseWebSocketConnection()

Disconnects the websocket while setting the auto-reconnect value to false, allowing purposeful disconnects that do not dump existing . NOTE: You will receive an error on the subscription (should be a WebSocket.WSError with code 1000) when the socket disconnects. ALSO NOTE: To reconnect after calling this, you will need to call resumeWebSocketConnection.

resumeWebSocketConnection(autoReconnect:)

public func resumeWebSocketConnection(autoReconnect: Bool = true)

Reconnects a paused web socket.

  • Parameter autoReconnect: true if you want the websocket to automatically reconnect if the connection drops. Defaults to true.

Parameters

NameDescription
autoReconnecttrue if you want the websocket to automatically reconnect if the connection drops. Defaults to true.
Next
Introduction
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company