npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@solace-community/graphql-solace-subscriptions

v1.0.6

Published

A graphql-subscriptions PubSub Engine using the Solace PubSub+ APIs

Downloads

7

Readme

Contributor Covenant

graphql-solace-subscriptions

Overview

This package implements the AsyncIterator Interface and PubSubEngine Interface from the graphql-subscriptions package. It allows you to connect your subscriptions manager to the Solace PubSub+ broker to support a horizontally scalable subscriptions setup. You can also take advantage of many Solace features such as EventMesh, TopicToQueueMapping etc to liberate your GraphQL events to outside your GraphQL ecosystem.

Installation

npm install @solace-community/graphql-solace-subscriptions

Using the AsyncIterator Interface

Define your GraphQL schema with a Subscription type.

schema {
  query: Query
  mutation: Mutation
  subscription: Subscription
}

type Subscription {
    somethingChanged: Result
}

type Result {
    id: String
}

Now, create a SolacePubSub instance.

import { SolacePubSub } from '@solace-community/graphql-solace-subscriptions';
const pubsub = await SolacePubSub.startWithDefaultOptions("GRAPH_QL_QUEUE"); // connecting to ws://localhost:8080 by default

Now, implement the Subscriptions type resolver, using pubsub.asyncIterator to map the event you need.

const SOMETHING_CHANGED_TOPIC = 'SOMETHING/CHANGED';

export const resolvers = {
  Subscription: {
    somethingChanged: {
      subscribe: () => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC)
    }
  }
}

Subscriptions resolvers are not a function, but an object with subscribe method, that returns AsyncIterable.

The AsyncIterator method will tell the Solace client to listen for messages from the Solace broker on the topic provided via a Queue, and wraps that listener in an AsyncIterator object.

When messages are received from the topic, those messages can be returned back to connected clients.

pubsub.publish can be used to send messages to a given topic.

pubsub.publish(SOMETHING_CHANGED_TOPIC, { somethingChanged: { id: "123" }});

Dynamically Create a Topic Based on Subscription Args Passed on the Query:

export const resolvers = {
  Subscription: {
    somethingChanged: {
      subscribe: (_, args) => pubsub.asyncIterator(`${SOMETHING_CHANGED_TOPIC}/${args.relevantId}`),
    },
  },
}

Using Arguments and Payload to Filter Events

import { withFilter } from 'graphql-subscriptions';

export const resolvers = {
  Subscription: {
    somethingChanged: {
      subscribe: withFilter(
        (_, args) => pubsub.asyncIterator(`${SOMETHING_CHANGED_TOPIC}/${args.relevantId}`),
        (payload, variables) => payload.somethingChanged.id === variables.relevantId,
      ),
    },
  },
}

Passing your own properties object

The basic usage is great for development and you will be able to connect to a locally hosted Solace PubSub+ event broker. But if you wanted to connect to a specific host, you can inject your own Solace properties.

import { SolacePubSub, SolacePubSubOptions } from '@solace-community/graphql-solace-subscriptions';

let solacePubSubOptions = new SolacePubSubOptions("wss://host:8081","vpn1","user","password");


const pubsub = await SolacePubSub.startWithSolaceOptions("GRAPH_QL_QUEUE",solacePubSubOptions);

Passing your own Solace Session

If you want to take advantage of a different authentication mechanism, you have the ability to inject a fully instantiated Solace session into the SolacePubSub object.

import { SolacePubSub } from '@solace-community/graphql-solace-subscriptions';
import solace from 'solclientjs';

let session: solace.Session;

//instantiate your solace session


const pubsub = await SolacePubSub.startWithSolaceSession("GRAPH_QL_QUEUE",session);

Resources

This is not an officially supported Solace product.

For more information try these resources:

  • Ask the Solace Community
  • The Solace Developer Portal website at: https://solace.dev

Contributing

Contributions are encouraged! Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

See the list of contributors who participated in this project.

License

See the LICENSE file for details.