0.4.0 • Published 2 years ago

graphql-signalr-subscriptions-withreconnect v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

SignalR GraphQL Subscriptions npm - SignalR package

This package contains support for Apollo GraphQL Subscriptions, using the Azure SignalR Service.

Installation

Install via npm or GitHub Packages:

$> npm install --save @graphql-signalr-subscriptions-withreconnect

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"]),
    },
  },
};