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)
- HyBi drafts 07-12 (Use the option
protocolVersion: 8
) - HyBi drafts 13-17 (Current default, alternatively option
protocolVersion: 13
)
npm install graphql-subscriber
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 */
);