Skip to content

Commit 3949ec7

Browse files
committed
Update ws docs
1 parent c5190a7 commit 3949ec7

1 file changed

Lines changed: 20 additions & 78 deletions

File tree

Lines changed: 20 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: WebSocket Link
2+
title: WebSocketLink
33
description: Execute subscriptions (or other operations) over WebSocket with the subscriptions-transport-ws library
44
---
55

@@ -11,89 +11,31 @@ Whichever library you use, make sure you use the _same_ library in your server a
1111

1212
</Caution>
1313

14-
The `WebSocketLink` is a [terminating link](./introduction/#the-terminating-link) that's used most commonly with GraphQL [subscriptions](../../data/subscriptions/) (which usually communicate over WebSocket), although you can send queries and mutations over WebSocket as well.
14+
<DocBlock
15+
canonicalReference="@apollo/client/link/ws!WebSocketLink:class"
16+
customOrder={["summary", "remarks", "example"]}
17+
/>
1518

16-
`WebSocketLink` requires the [`subscriptions-transport-ws`](https://github.com/apollographql/subscriptions-transport-ws) library. Install it in your project like so:
19+
## Constructor signature
1720

18-
```shell
19-
npm install subscriptions-transport-ws
21+
```ts
22+
constructor(
23+
paramsOrClient: WebSocketLink.Configuration | SubscriptionClient
24+
): WebSocketLink
2025
```
2126

22-
## Constructor
27+
## Installation
2328

24-
```js
25-
import { WebSocketLink } from "@apollo/client/link/ws";
26-
import { SubscriptionClient } from "subscriptions-transport-ws";
29+
`WebSocketLink` requires the [`subscriptions-transport-ws`](https://github.com/apollographql/subscriptions-transport-ws) library. Install it in your project:
2730

28-
const link = new WebSocketLink(
29-
new SubscriptionClient("ws://localhost:4000/graphql", {
30-
reconnect: true,
31-
})
32-
);
31+
```shell
32+
npm install subscriptions-transport-ws
3333
```
3434

35-
### Options
36-
37-
The `WebSocketLink` constructor takes either a `SubscriptionClient` object or an options object with the following fields. (These options are passed directly to the `SubscriptionClient` constructor.)
38-
39-
<table class="field-table">
40-
<thead>
41-
<tr>
42-
<th>Name /<br/>Type</th>
43-
<th>Description</th>
44-
</tr>
45-
</thead>
46-
47-
<tbody>
48-
<tr class="required">
49-
<td>
50-
51-
###### `uri`
52-
53-
`String`
54-
55-
</td>
56-
<td>
57-
58-
**Required.** The URL of the WebSocket endpoint to connect to (e.g., `ws://localhost:4000/subscriptions`).
59-
60-
</td>
61-
</tr>
62-
63-
<tr>
64-
<td>
65-
66-
###### `options`
67-
68-
`Object`
69-
70-
</td>
71-
<td>
72-
73-
Options for configuring the WebSocket connection.
74-
75-
[See supported options](https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts#L61-L71)
76-
77-
</td>
78-
</tr>
79-
80-
<tr>
81-
<td>
82-
83-
###### `webSocketImpl`
84-
85-
`Object`
86-
87-
</td>
88-
<td>
89-
90-
A W3C-compliant WebSocket implementation to use. Provide this if your environment does not provide native WebSocket support (for example, in Node.js).
91-
92-
</td>
93-
</tr>
94-
</tbody>
95-
</table>
96-
97-
## Usage
35+
## Types
9836

99-
See [Subscriptions](../../data/subscriptions/).
37+
<InterfaceDetails
38+
canonicalReference="@apollo/client/link/ws!WebSocketLink.Configuration:interface"
39+
headingLevel={3}
40+
displayName="WebSocketLink.Configuration"
41+
/>

0 commit comments

Comments
 (0)