{"_id":"@daisychain/graphql-mongoose-subscriptions","_rev":"3-36c93c57df990ad17c164d93140be418","name":"@daisychain/graphql-mongoose-subscriptions","dist-tags":{"latest":"2.0.2"},"versions":{"2.0.0":{"name":"@daisychain/graphql-mongoose-subscriptions","version":"2.0.0","description":"A graphql-subscriptions PubSub Engine using mongoose","main":"dist/index.js","repository":{"type":"git","url":"git+https://github.com/Anthbs/graphql-mongoose-subscriptions.git"},"keywords":["graphql","mongoose","apollo","subscriptions"],"author":{"name":"Nickolasmv"},"license":"MIT","bugs":{"url":"https://github.com/Anthbs/graphql-mongoose-subscriptions/issues"},"homepage":"https://github.com/Anthbs/graphql-mongoose-subscriptions","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"babel src -d dist","prepublishOnly":"npm run build"},"dependencies":{"iterall":"^1.3.0"},"peerDependencies":{"mongoose":"^6.6.0","graphql-subscriptions":"^2.0.0"},"devDependencies":{"@types/chai":"^4.2.12","@types/chai-as-promised":"^7.1.3","@types/mocha":"^8.0.3","@types/node":"14.6.4","babel-cli":"^6.26.0","babel-preset-es2015":"^6.24.1","chai":"^4.2.0","chai-as-promised":"^7.1.1","eslint":"^7.7.0","graphql":"^15.3.0","graphql-subscriptions":"^2.0.0","mocha":"^8.1.3"},"gitHead":"9e4bab22a2a16d980c7616feef815611412987d2","_id":"@daisychain/graphql-mongoose-subscriptions@2.0.0","_nodeVersion":"18.14.1","_npmVersion":"9.3.1","dist":{"integrity":"sha512-XBLDtaciES28sY6VfI70UpdQRiLo9NaRSzRUemsQOk6odYPWnikNDbIdCXR641z8SZc13RaU7cU+IW+PGHTrmQ==","shasum":"30649236abbc61ea40c21be4d04e2332e2d1fb48","tarball":"https://registry.npmjs.org/@daisychain/graphql-mongoose-subscriptions/-/graphql-mongoose-subscriptions-2.0.0.tgz","fileCount":7,"unpackedSize":14990,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCLYM2qUU/IlrdurYdCvbCcjt98+W8rNXrJghBdeTsNWwIgePrGu1o9WG1IPw1hOIAiY/pJh0kEqulVNysD/sApLM0="}]},"_npmUser":{"name":"anthbs","email":"Anthbs@gmail.com"},"directories":{},"maintainers":[{"name":"david_dragovich","email":"david@dragovich.co.nz"},{"name":"anthbs","email":"Anthbs@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mongoose-subscriptions_2.0.0_1683762812391_0.5984327220513475"},"_hasShrinkwrap":false},"2.0.1":{"name":"@daisychain/graphql-mongoose-subscriptions","version":"2.0.1","description":"A graphql-subscriptions PubSub Engine using mongoose","main":"dist/index.js","repository":{"type":"git","url":"git+https://github.com/Anthbs/graphql-mongoose-subscriptions.git"},"keywords":["graphql","mongoose","apollo","subscriptions"],"author":{"name":"Nickolasmv"},"license":"MIT","bugs":{"url":"https://github.com/Anthbs/graphql-mongoose-subscriptions/issues"},"homepage":"https://github.com/Anthbs/graphql-mongoose-subscriptions","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"babel src -d dist","prepublishOnly":"npm run build"},"dependencies":{"iterall":"^1.3.0"},"peerDependencies":{"mongoose":"^6.6.0","graphql-subscriptions":"^2.0.0"},"devDependencies":{"@types/chai":"^4.2.12","@types/chai-as-promised":"^7.1.3","@types/mocha":"^8.0.3","@types/node":"14.6.4","babel-cli":"^6.26.0","babel-preset-es2015":"^6.24.1","chai":"^4.2.0","chai-as-promised":"^7.1.1","eslint":"^7.7.0","graphql":"^15.3.0","graphql-subscriptions":"^2.0.0","mocha":"^8.1.3"},"gitHead":"9e4bab22a2a16d980c7616feef815611412987d2","_id":"@daisychain/graphql-mongoose-subscriptions@2.0.1","_nodeVersion":"18.14.1","_npmVersion":"9.3.1","dist":{"integrity":"sha512-Z1MwYUqJUOAX75qdfqabk2UvyVIimObzXuLrmW81FKXK8LYQVcKj+xXQR/ljNVumkoVq49NZIHQYrMocPFFziw==","shasum":"957655e7d03237e0ef227ba0a0c83695e073737c","tarball":"https://registry.npmjs.org/@daisychain/graphql-mongoose-subscriptions/-/graphql-mongoose-subscriptions-2.0.1.tgz","fileCount":7,"unpackedSize":15136,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC2t5QenRd4p4eWNxIE5bjDxXyOGvezjTSqbNyqoveKdwIgPX09VROpDpFwpjMIySVwUkHrvAIUt+nEEFSjSjnQvRs="}]},"_npmUser":{"name":"anthbs","email":"Anthbs@gmail.com"},"directories":{},"maintainers":[{"name":"david_dragovich","email":"david@dragovich.co.nz"},{"name":"anthbs","email":"Anthbs@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mongoose-subscriptions_2.0.1_1683763051456_0.6416032094020194"},"_hasShrinkwrap":false},"2.0.2":{"name":"@daisychain/graphql-mongoose-subscriptions","version":"2.0.2","description":"A graphql-subscriptions PubSub Engine using mongoose","main":"dist/index.js","repository":{"type":"git","url":"git+https://github.com/Anthbs/graphql-mongoose-subscriptions.git"},"keywords":["graphql","mongoose","apollo","subscriptions"],"author":{"name":"Nickolasmv"},"license":"MIT","bugs":{"url":"https://github.com/Anthbs/graphql-mongoose-subscriptions/issues"},"homepage":"https://github.com/Anthbs/graphql-mongoose-subscriptions","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"babel src -d dist","prepublishOnly":"npm run build"},"dependencies":{"iterall":"^1.3.0"},"peerDependencies":{"mongoose":"^6.6.0","graphql-subscriptions":"^2.0.0"},"devDependencies":{"@types/chai":"^4.2.12","@types/chai-as-promised":"^7.1.3","@types/mocha":"^8.0.3","@types/node":"14.6.4","babel-cli":"^6.26.0","babel-preset-es2015":"^6.24.1","chai":"^4.2.0","chai-as-promised":"^7.1.1","eslint":"^7.7.0","graphql":"^15.3.0","graphql-subscriptions":"^2.0.0","mocha":"^8.1.3"},"gitHead":"9e4bab22a2a16d980c7616feef815611412987d2","_id":"@daisychain/graphql-mongoose-subscriptions@2.0.2","_nodeVersion":"18.14.1","_npmVersion":"9.3.1","dist":{"integrity":"sha512-px5IHK381cTtCF+3FIwThRLQzs2UmH2Gp+8jg4Nda9txaPlfWZHddHDI2Weqr/uFJPyZ4PLD7uzlt/RXyd2eaw==","shasum":"f42e429e62a114c9f32cac9f789c8de1e572886b","tarball":"https://registry.npmjs.org/@daisychain/graphql-mongoose-subscriptions/-/graphql-mongoose-subscriptions-2.0.2.tgz","fileCount":7,"unpackedSize":15136,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC+zXkGpSxKrz59NBYz+Bb+a5UEtCLP9cZIs00atiZKmwIhAP5k1IGOfPJ351SyDh/vHkvxN/JhoP14eCPFeN0T5HoQ"}]},"_npmUser":{"name":"anthbs","email":"Anthbs@gmail.com"},"directories":{},"maintainers":[{"name":"david_dragovich","email":"david@dragovich.co.nz"},{"name":"anthbs","email":"Anthbs@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mongoose-subscriptions_2.0.2_1683765361480_0.5472932362793534"},"_hasShrinkwrap":false}},"time":{"created":"2023-05-10T23:53:32.391Z","2.0.0":"2023-05-10T23:53:32.547Z","modified":"2023-05-11T00:36:01.806Z","2.0.1":"2023-05-10T23:57:31.589Z","2.0.2":"2023-05-11T00:36:01.685Z"},"maintainers":[{"name":"david_dragovich","email":"david@dragovich.co.nz"},{"name":"anthbs","email":"Anthbs@gmail.com"}],"description":"A graphql-subscriptions PubSub Engine using mongoose","homepage":"https://github.com/Anthbs/graphql-mongoose-subscriptions","keywords":["graphql","mongoose","apollo","subscriptions"],"repository":{"type":"git","url":"git+https://github.com/Anthbs/graphql-mongoose-subscriptions.git"},"author":{"name":"Nickolasmv"},"bugs":{"url":"https://github.com/Anthbs/graphql-mongoose-subscriptions/issues"},"license":"MIT","readme":"# graphql-mongoose-subscriptions\r\n\r\n[![Dependabot badge](https://flat.badgen.net/Nickolasmv/graphql-mongoose-subscriptions?icon=dependabot)](https://dependabot.com/)\r\n[![Build Status](https://travis-ci.org/Nickolasmv/graphql-mongoose-subscriptions.svg?branch=master)](https://travis-ci.org/Nickolasmv/graphql-mongoose-subscriptions)\r\n\r\nThis package implements the PubSubEngine Interface from the [graphql-subscriptions](https://github.com/apollographql/graphql-subscriptions) package and also the new AsyncIterator interface. \r\nIt allows you to connect your subscriptions manager to a mongoose Pub Sub mechanism to support \r\nmultiple subscription manager instances.\r\n\r\n## Installation\r\nAt first, install the `graphql-mongoose-subscriptions` package: \r\n```\r\nnpm install graphql-mongoose-subscriptions\r\n```\r\n\r\nAs the [graphql-subscriptions](https://github.com/apollographql/graphql-subscriptions) package is declared as a peer dependency, you might receive warning about an unmet peer dependency if it's not installed already by one of your other packages. In that case you also need to install it too:\r\n```\r\nnpm install graphql-subscriptions\r\n```\r\n   \r\n## Using as AsyncIterator\r\n\r\nDefine your GraphQL schema with a `Subscription` type:\r\n\r\n```graphql\r\nschema {\r\n  query: Query\r\n  mutation: Mutation\r\n  subscription: Subscription\r\n}\r\n\r\ntype Subscription {\r\n    somethingChanged: Result\r\n}\r\n\r\ntype Result {\r\n    id: String\r\n}\r\n```\r\n\r\nNow, let's create a simple `MongoosePubSub` instance:\r\n\r\n```javascript\r\nimport { MongoosePubSub } from 'graphql-mongoose-subscriptions';\r\nconst pubsub = new MongoosePubSub();\r\n```\r\n\r\nNow, implement your Subscriptions type resolver, using the `pubsub.asyncIterator` to map the event you need:\r\n\r\n```javascript\r\nconst SOMETHING_CHANGED_TOPIC = 'something_changed';\r\n\r\nexport const resolvers = {\r\n  Subscription: {\r\n    somethingChanged: {\r\n      subscribe: () => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC),\r\n    },\r\n  },\r\n}\r\n```\r\n\r\n> Subscriptions resolvers are not a function, but an object with `subscribe` method, that returns `AsyncIterable`.\r\n\r\nCalling the method `asyncIterator` of the `MongoosePubSub` instance will send mongoose a `SUBSCRIBE` message to the topic provided and will return an `AsyncIterator` binded to the MongoosePubSub instance and listens to any event published on that topic.\r\nNow, the GraphQL engine knows that `somethingChanged` is a subscription, and every time we will use `pubsub.publish` over this topic, the `MongoosePubSub` will `PUBLISH` the event over mongoose to all other subscribed instances and those in their turn will emit the event to GraphQL using the `next` callback given by the GraphQL engine.\r\n\r\n```js\r\npubsub.publish(SOMETHING_CHANGED_TOPIC, { somethingChanged: { id: \"123\" }});\r\n```\r\n\r\n## Dynamically create a topic based on subscription args passed on the query\r\n\r\n```javascript\r\nexport const resolvers = {\r\n  Subscription: {\r\n    somethingChanged: {\r\n      subscribe: (_, args) => pubsub.asyncIterator(`${SOMETHING_CHANGED_TOPIC}.${args.relevantId}`),\r\n    },\r\n  },\r\n}\r\n```\r\n\r\n## Using a pattern on subscription\r\n\r\n```javascript\r\nexport const resolvers = {\r\n  Subscription: {\r\n    somethingChanged: {\r\n      subscribe: (_, args) => pubsub.asyncIterator(`${SOMETHING_CHANGED_TOPIC}.${args.relevantId}.*`, { pattern: true })\r\n    },\r\n  },\r\n}\r\n```\r\n\r\n## Using both arguments and payload to filter events\r\n\r\n```javascript\r\nimport { withFilter } from 'graphql-subscriptions';\r\n\r\nexport const resolvers = {\r\n  Subscription: {\r\n    somethingChanged: {\r\n      subscribe: withFilter(\r\n        (_, args) => pubsub.asyncIterator(`${SOMETHING_CHANGED_TOPIC}.${args.relevantId}`),\r\n        (payload, variables) => payload.somethingChanged.id === variables.relevantId,\r\n      ),\r\n    },\r\n  },\r\n}\r\n```\r\n\r\n## Creating the mongoose Client\r\n\r\nThe basic usage is great for development and you will be able to connect to a mongoose server running on your system seamlessly. For production usage, it is recommended to send a mongoose client from the using code and pass in any options you would like to use. e.g: Connection retry strategy.\r\n\r\n```javascript\r\nimport { MongoosePubSub } from 'graphql-mongoose-subscriptions';\r\nimport mongoose from 'mongoose'; \r\n\r\nconst mongoose = require('mongoose');\r\nmongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});\r\nconst pubsub = new MongoosePubSub();\r\n```\r\n\r\n```OR\r\nconst pubsub = new MongoosePubSub({mongooseOptions:{url:'mongodb://localhost:27017/test',options:{useNewUrlParser: true, useUnifiedTopology: true}}})\r\n```\r\n\r\n","readmeFilename":"README.md"}