WebSocket Link
Execute subscriptions (or other operations) over WebSocket with the subscriptions-transport-ws library
⚠️ We no longer recommend using WebSocketLink
or the subscriptions-transport-ws
library, because the library is not actively maintained. To execute subscriptions, We instead recommend using the newer graphql-ws
library with the accompanying GraphQLWsLink
Whichever library you use, make sure you use the same library in your server and any clients you support. For more information, see
The WebSocketLink
is a
WebSocketLink
requires the subscriptions-transport-ws
npm install subscriptions-transport-ws
Constructor
import { WebSocketLink } from "@apollo/client/link/ws";import { SubscriptionClient } from "subscriptions-transport-ws";const link = new WebSocketLink(new SubscriptionClient("ws://localhost:4000/graphql", {reconnect: true}));
Options
The WebSocketLink
constructor takes either a SubscriptionClient
object or an options object with the following fields. (These options are passed directly to the SubscriptionClient
constructor.)
Name / Type | Description |
---|---|
uri
| Required. The URL of the WebSocket endpoint to connect to (e.g., |
options
| Options for configuring the WebSocket connection. |
webSocketImpl
| A W3C-compliant WebSocket implementation to use. Provide this if your environment does not provide native WebSocket support (for example, in Node.js). |
Usage
See