Socket
Book a DemoInstallSign in
Socket

graphql-sqs-subscriptions

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-sqs-subscriptions

This package implements the PubSubEngine Interface from the [graphql-subscriptions](https://github.com/apollographql/graphql-subscriptions) package. It allows you to connect your subscriptions manager to an AWS SQS (Simple Queue Service) queue.

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

graphql-sqs-subscriptions

This package implements the PubSubEngine Interface from the graphql-subscriptions package. It allows you to connect your subscriptions manager to an AWS SQS (Simple Queue Service) queue.

Installation

npm install graphql-sqs-subscriptions

// or

yarn install graphql-sqs-subscriptions

Usage

Define your GraphQL schema with a Subscription type:

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

type Subscription {
  fooAdded: Result
}

type Result {
  id: String
}

Create a simple SQSPubSub instance, passing in your AWS API keys and region:

import { SQSPubSub } from "graphql-sqs-subscriptions";

const pubsub = new SQSPubSub({
  accessKeyId: AWS_ACCESS_KEY_ID,
  secretAccessKey: AWS_SECRET_ACCESS_KEY,
  region: AWS_REGION
});

Now, implement your Subscription resolver, using the pubsub.asyncIterator method, passing in the relevant trigger name:

export const resolvers = {
  Subscription: {
    fooAdded: {
      subscribe: () => pubsub.asyncIterator("foo_added")
    }
  }
};

Calling the asyncIterator method will subscribe the SQSPubSub instance to any new message on the SQS queue.

Any time pubsub.publish is then called, with a matching trigger name (i.e. "foo_added"), GraphQL will publish the data to all subscribed clients.

pubsub.publish("foo_added", { fooAdded: { id: "123" } });

Keywords

amazon web services

FAQs

Package last updated on 02 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts