1 | ---
|
2 | title: apollo-link-ws
|
3 | description: Send GraphQL operations over a WebSocket. Works with GraphQL Subscriptions.
|
4 | ---
|
5 |
|
6 | This link is particularly useful to use GraphQL Subscriptions, but it will also allow you to send GraphQL queries and mutations over WebSockets as well.
|
7 |
|
8 | ```js
|
9 | import { WebSocketLink } from "apollo-link-ws";
|
10 | import { SubscriptionClient } from "subscriptions-transport-ws";
|
11 |
|
12 | const GRAPHQL_ENDPOINT = "ws://localhost:3000/graphql";
|
13 |
|
14 | const client = new SubscriptionClient(GRAPHQL_ENDPOINT, {
|
15 | reconnect: true
|
16 | });
|
17 |
|
18 | const link = new WebSocketLink(client);
|
19 | ```
|
20 |
|
21 | <h2 id="options">Options</h2>
|
22 |
|
23 | 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:
|
24 |
|
25 | * `uri`: a string endpoint to connect to
|
26 | * `options`: a set of options to pass to a new Subscription Client
|
27 | * `webSocketImpl`: a custom WebSocket implementation
|
28 |
|
29 | By default, this link uses the [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws) library for the transport.
|