graphql-subscriber
v1.0.3
Published
A simple graphql subscription client
Downloads
1
Readme
GraphQl Subscriber
GraphQl subscriber is is a simple to use, fast, and reliable graphQl subscription implemented based on [GraphQL over WebSocket Protocol
] (https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md)
Table of Contents
Protocol support
- HyBi drafts 07-12 (Use the option
protocolVersion: 8
) - HyBi drafts 13-17 (Current default, alternatively option
protocolVersion: 13
)
Installing
npm install graphql-subscriber
Creating a subscription
const SubscriptionManager = require("graphql-subscriber");
/**
* @note if you are connecting to an `websocket` endpoint without a port
* number, you can omit the port `parameter`
* */
const client = new SubscriptionManager("ws:websocket-url", 4000);
/**
* Create a subscription query `string`. The library only accept string at the moment
* */
const sub = `subscription {
parcelGetPriceDone {
success
message
code
errorCode
data
}
}`;
client.subscribe({ query: sub, operationName: "parcelGetPriceDone" }, (data) =>
/** A callback to process the subscription data */
);