UNPKG

1.07 kBMarkdownView Raw
1---
2title: WebSocket Link
3---
4
5## Purpose
6An 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
14import { WebSocketLink } from "apollo-link-ws";
15import { SubscriptionClient } from 'subscriptions-transport-ws';
16
17const GRAPHQL_ENDPOINT = 'ws://localhost:3000/graphql';
18
19const client = new SubscriptionClient(GRAPHQL_ENDPOINT, {
20 reconnect: true,
21});
22
23const link = new WebSocketLink(client);
24```
25
26## Options
27WS 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
33By default, this link uses the [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws) library for the transport.
34
35## Context
36The WS Link does not use any keys on the context.