docs/source/api/link/apollo-link-subscriptions.mdx
GraphQLWsLink requires the graphql-ws library. Install it in your project like so:
npm install graphql-ws
<DocBlock canonicalReference="@apollo/client/link/subscriptions!GraphQLWsLink:class" customOrder={["example"]} />
constructor(
client: Client
): GraphQLWsLink
The GraphQLWsLink constructor takes a single argument: a Client instance from the graphql-ws library. To create this instance, call the library's createClient function. This function requires a url option, which is the URL to your WebSocket server. WebSocket URLs typically start with ws:// or wss://.
See the ClientOptions documentation for more details on the supported options provided to the createClient function.
See the graphql-ws recipes for strategies on retrying failed connections from the client. We generally recommend this approach over retrying failed connections from the link chain or your components because it provides more detailed information on why the connection failed.
Alternatively, you can handle retries more generically within the link chain by using RetryLink. This link resends the operation to the terminating link upon failure.
See Subscriptions for more information on using subscription operations in Apollo Client.