https://github.com/hoangvvo/benzene-ws-client
Tiny WebSocket client for GraphQL over WebSocket Protocol
https://github.com/hoangvvo/benzene-ws-client
Last synced: 3 months ago
JSON representation
Tiny WebSocket client for GraphQL over WebSocket Protocol
- Host: GitHub
- URL: https://github.com/hoangvvo/benzene-ws-client
- Owner: hoangvvo
- License: mit
- Created: 2020-09-06T11:09:01.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2020-09-06T17:43:20.000Z (almost 5 years ago)
- Last Synced: 2025-02-09T21:41:17.805Z (4 months ago)
- Language: TypeScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# benzene-ws-client
[](https://www.npmjs.com/package/@benzene/worker)
[](https://bundlephobia.com/result?p=benzene-ws-client)> This package is only experimental and not tested. Only works with `@benzene/ws` for now.
The *tiny* client for the [modified GraphQL over WebSocket Protocol](https://github.com/hoangvvo/benzene/blob/main/packages/ws/PROTOCOL.md).
## Install
```bash
yarn add benzene-ws-client
```## Usage
```js
import { SubscriptionClient } from 'benzene-ws-client';const subscriptionClient = new SubscriptionClient('wss://localhost/graphql', options);
```#### urql
```js
import { Client, defaultExchanges, subscriptionExchange } from 'urql';const client = new Client({
url: '/graphql',
exchanges: [
...defaultExchanges,
subscriptionExchange({
forwardSubscription(operation) {
return subscriptionClient.request(operation);
},
}),
],
});
```#### @apollo/client
```js
import { WebSocketLink } from "@apollo/client/link/ws";const link = new WebSocketLink(subscriptionClient);
```## Options
| option | description | default |
| --- | --- | --- |
| reconnectionAttempts | Number of attempts to try reconnect on disconnection. | `0` (disabled) |
| genId | A function to generate unique subscription ids. Default to incremental ids. | `undefined` |