UNPKG

1.1 kBMarkdownView Raw
1---
2title: apollo-link-ws
3description: Send GraphQL operations over a WebSocket. Works with GraphQL Subscriptions.
4---
5
6This 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
9import { WebSocketLink } from "apollo-link-ws";
10import { SubscriptionClient } from "subscriptions-transport-ws";
11
12const GRAPHQL_ENDPOINT = "ws://localhost:3000/graphql";
13
14const client = new SubscriptionClient(GRAPHQL_ENDPOINT, {
15 reconnect: true
16});
17
18const link = new WebSocketLink(client);
19```
20
21<h2 id="options">Options</h2>
22
23WS 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
29By default, this link uses the [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws) library for the transport.