1 | ---
|
2 | title: WebSocket Link
|
3 | ---
|
4 |
|
5 | ## Purpose
|
6 | An Apollo Link to allow sending a request over a web socket.
|
7 |
|
8 | ## Installation
|
9 |
|
10 | `npm install apollo-link-ws --save`
|
11 |
|
12 | ## Usage
|
13 | ```js
|
14 | import { WebSocketLink } from "apollo-link-ws";
|
15 | import { SubscriptionClient } from 'subscriptions-transport-ws';
|
16 |
|
17 | const GRAPHQL_ENDPOINT = 'ws://localhost:3000/graphql';
|
18 |
|
19 | const client = new SubscriptionClient(GRAPHQL_ENDPOINT, {
|
20 | reconnect: true,
|
21 | });
|
22 |
|
23 | const link = new WebSocketLink(client);
|
24 | ```
|
25 |
|
26 | ## Options
|
27 | WS Link takes either a subscription client or an object with three options on it to customize the behavior of the link. Takes the following possible keys in the configuration object:
|
28 |
|
29 | - `uri`: a string endpoint to connect to
|
30 | - `options`: a set of options to pass to a new Subscription Client
|
31 | - `webSocketImpl`: a custom WebSocket implementation
|
32 |
|
33 | By default, this link uses the [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws) library for the transport.
|
34 |
|
35 | ## Context
|
36 | The WS Link does not use any keys on the context.
|