@aaronpowell/graphql-signalr-subscriptions
v0.3.0
Published
A GraphQL subscriptions library using Azure SignalR Service
Downloads
40
Readme
SignalR GraphQL Subscriptions
This package contains support for Apollo GraphQL Subscriptions, using the Azure SignalR Service.
Installation
Install via npm or GitHub Packages:
$> npm install --save @aaronpowell/graphql-signalr-subscriptions
Usage
You'll need a SignalR Service account (if you don't have an Azure account sign up for free). Copy the connection string and provide it when you create an instance of SignalRPubSub
:
import { SignalRPubSub } from "@aaronpowell/graphql-signalr-subscriptions";
const signalrPubSub = new SignalRPubSub("<connection string>");
When your server is ready, you can start the pubsub client:
signalrPubSub
.start()
.then(() => console.log("SignalR PubSub is up and running"))
.catch((error) => console.error(error));
From within a resolver, you use it the same as any other pubsub implementation:
export const resolvers = {
Query: {
hello() {
signalrPubSub.publish("TESTING", { getMessage: "Hello I'm a message" });
return "Some message";
},
},
Subscription: {
getMessage: {
subscribe: () => signalrPubSub.asyncIterator(["TESTING"]),
},
},
};