🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

graphql-subscriptions-client

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-subscriptions-client - npm Package Compare versions

Comparing version

to
0.16.1

2

package.json
{
"name": "graphql-subscriptions-client",
"version": "0.16.0",
"version": "0.16.1",
"description": "A simpler client for graphql subscriptions based on apollographql/subscriptions-transport-ws",

@@ -5,0 +5,0 @@ "module": "dist/esm/index.js",

# graphql-subscriptions-client
## graphql-ws
This library works fine, but you may consider using [graphql-ws](https://github.com/enisdenjo/graphql-ws). It's popular, well-maintained, works, and has zero dependencies.
## What is this package
This is based directly on the client from [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws). As the name suggests, it's only for use as a client. It uses native websockets to communicate with a graphql server which is using ['graphql-ws' protocol](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md). It plays nice with rollup, too.

@@ -19,8 +25,8 @@

If you have a apollo-server instance you can use this for subscriptions only, pass all requests over the websocket.
The API is similar to what's described at [subscriptions-transport-ws docs](https://github.com/apollographql/subscriptions-transport-ws#api-docs) except that it doesn't support middleware and requires queries to be strings.
If you have a apollo-server instance you can use this for subscriptions only, pass all requests over the websocket.
The API is similar to what's described at [subscriptions-transport-ws docs](https://github.com/apollographql/subscriptions-transport-ws#api-docs) except that it doesn't support middleware and requires queries to be strings.
Also, this client supports batch messages as arrays from the server, and they will be processed as if they were received one after another, for example:
Also, this client supports batch messages as arrays from the server, and they will be processed as if they were received one after another, for example:
```
```javascript
[{ id: "1", type: "data", ... }, { id: "1", type: "complete" }]

@@ -30,6 +36,6 @@ ```

```js
import { SubscriptionClient } from 'graphql-subscriptions-client';
import { SubscriptionClient } from "graphql-subscriptions-client";
// get ready
const GRAPHQL_ENDPOINT = 'ws://localhost:3000/graphql';
const GRAPHQL_ENDPOINT = "ws://localhost:3000/graphql";

@@ -40,3 +46,3 @@ const query = `subscription onNewItem {

}
}`
}`;

@@ -47,9 +53,9 @@ // set up the client, which can be reused

lazy: true, // only connect when there is a query
connectionCallback: error => {
error && console.error(error)
}
connectionCallback: (error) => {
error && console.error(error);
},
});
// make the actual request
client.request({query})
client.request({ query });

@@ -59,11 +65,12 @@ // the above doesn't do much though

// call subscription.unsubscribe() later to clean up
const subscription = client.request({query})
const subscription = client
.request({ query })
// so lets actually do something with the response
.subscribe({
next ({data}) {
next({ data }) {
if (data) {
console.log('We got something!', data)
console.log("We got something!", data);
}
}
})
},
});
```

@@ -70,0 +77,0 @@