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

graphql-aws-iot-server

v0.0.1

Published

Serverless graphql transport for graphql queries mutations and subascriptions

Downloads

4

Readme

graphql-aws-iot-server (serverless and lambda friendly!)

(Work in progress!) An adaptation of the Apollo Subscriptions Ws Transport to support serverless GraphQL queries, mutations and subscriptions using AWS iot websockets.

Architecture Diagram

Architecture Diagram

Functions

SubscriptionManager

  • The manager publishes all socket to ${appPrefix}/in/clientId where clientId is the unique identifier per client connected on AWS IoT
  • For queries / mutations the manager immediately published the result upon processing the query.
  • For subscriptions the following process occurs:
  1. Validate subscription with GraphQLSchema
  2. Store subscriptions information in DB. You provide the function to store a new subscription to the db. The addSubscription must return a promise on completion. The input parameter to this function is of the following format:
interface Subscription {
  clientId: string;
  query: string;
  subscriptionName: string;
  subscriptionId: string;
  variableValues: { [key: string]: any };
}
  1. The GraphQlServer Package exports a PubSub class which is used to publish a new message. The PubSub class has a publish method which invokes the SubscriptionPublisherFunction. In your GraphQL Schema you invoke the publish method in the same way as you would if you were using the servered subscriptions transport. The method returns a promise to ensure completion.
return pubsub.publish('NEW_TODO', { teamTodoAdded: input }).then(_ => {...});
  1. You are also required to provide a removeSubscriptionFunction that returns a promise on completion. The parameters to this function which are provided by this server package will be subscriptionName and clientId. We recommend having and index to retrieve a subscription based on those properties.

SubscriptionPublisher

The publisher has one public method executeQueriesAndSendMessages which takes an array of subscriptions in the same format as they were stored and executes the queries and then publishes the result to the active subscribers. This method returns a promise to ensure completion.

The triggerNameToSubscriptionNamesMap and the triggerNameToFilterFunctionsMap is defined in your own lambda function before invoking the publisher.

  1. Your application Subscription Publisher will get triggerName and payload in the event object.
  2. Use the triggerNameToSubscriptionNamesMap to identify all the subscriptionNames that you need to retrieve subscription rows for.
  3. Retrieve subscriptions from the db. Ideally for each subscription pass in the array of subscription rows to the executeQueriesAndSendMessages.
  4. Execute the filterFunction for the triggerName on each row.
  5. For those rows that return true in the filter function, you can run the executeQueriesAndSendMessages with an array of subscriptions and payload as the parameters.
  6. You can choose to run this function in batches as per your application logic.

The database choice and how you choose to batch has been purposely left to the application rather than this helper package for reusability.

Best Practices

  • We recommend using the AWS IoT disconnect lifecycle event to remove active subscriptions from a clientId. See Demo Codefor an example of a pruner on the aws iot disconnect event as well as a full working demo.

  • For scale you can publish aws iot events to a kinesis stream which then invokes your SubscriptionManager lambda function

See full example app at

Source Code Demo Code

Demo URL Demo URL