{"_id":"@brettjashford/graphql-mqtt-subscriptions","_rev":"1-d8c8f4bae9710b84499fc0814f93efa4","name":"@brettjashford/graphql-mqtt-subscriptions","dist-tags":{"latest":"1.1.4","next":"1.1.5"},"versions":{"1.1.4":{"name":"@brettjashford/graphql-mqtt-subscriptions","version":"1.1.4","description":"A graphql-subscriptions PubSub Engine using mqtt protocol","publishConfig":{"access":"public"},"main":"dist/index.js","repository":{"type":"git","url":"https://github.com/aerogear/graphql-mqtt-subscriptions.git"},"keywords":["graphql","mqtt","apollo","subscriptions"],"author":{"name":"David Yahalomi"},"license":"MIT","bugs":{"url":"https://github.com/aerogear/graphql-mqtt-subscriptions/issues"},"homepage":"https://github.com/aerogear/graphql-mqtt-subscriptions","scripts":{"compile":"tsc --noUnusedParameters --noUnusedLocals","test":"tsc && nyc --reporter=lcov mocha ./dist/test/tests.js","posttest":"npm run lint","lint":"tslint ./src/**/*.ts","watch":"tsc -w","integration":"npm run compile && mocha --reporter spec --full-trace --exit ./dist/test/integration-tests.js ","benchmark":"npm run compile && mocha --reporter spec --full-trace ./dist/test/benchmark.js ","release:prep":"./scripts/prepareRelease.sh","release:validate":"./scripts/validateRelease.sh","release:publish":"./scripts/publishRelease.sh"},"dependencies":{"iterall":"^1.2.2","mqtt":"^4.0.0"},"devDependencies":{"@istanbuljs/nyc-config-typescript":"0.1.3","@types/chai":"4.2.11","@types/chai-as-promised":"7.1.3","@types/graphql":"14.2.3","@types/mocha":"8.0.0","@types/node":"11.13.9","@types/simple-mock":"0.8.1","chai":"4.2.0","chai-as-promised":"7.1.1","coveralls":"3.1.0","graphql":"15.1.0","graphql-subscriptions":"1.1.0","mocha":"8.0.1","nyc":"15.1.0","simple-mock":"0.8.0","tslint":"5.20.1","typescript":"3.9.5"},"peerDependencies":{"graphql-subscriptions":"^1.1.0"},"typings":"dist/index.d.ts","typescript":{"definition":"dist/index.d.ts"},"nyc":{"extends":"@istanbuljs/nyc-config-typescript","all":true,"check-coverage":false,"exclude":["src/test/**/*.ts"]},"licenseText":"MIT License\n\nCopyright (c) 2016 David Yahalomi\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@brettjashford/graphql-mqtt-subscriptions@1.1.4","dist":{"shasum":"7022315245d16482c913cdc5d33c6ae6bb32f755","integrity":"sha512-YIonH+belDd9b/a15edSUa1AkBHBQHypTJuU/w+8Y+LubuoexAIxBMEeP5DVvj9zJZo13Ine+5vlZH6PRIWbsg==","tarball":"https://registry.npmjs.org/@brettjashford/graphql-mqtt-subscriptions/-/graphql-mqtt-subscriptions-1.1.4.tgz","fileCount":7,"unpackedSize":11901,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGw72lDRudko9sSmUTFYy8TjLB4Lftn/E9r4KBUO3g+FAiEAigBzpKyiAkgLfRFLkD8C7AWclEAWiWT0nbub7INvgO0="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJibEFNACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq0cg//fFXlbTm45liKjMrEPsywJBKDa63syZarz4x4rVOEvUNz7DDj\r\ntOxf39mUfxFh8zM5kpqIiDXM3Ag87l+swcxRPkIJQnJSAvg6AqHzevrVpnXC\r\nOmqDpD764E1tyUSS58GPvDKdqC10GScfARDHlvA7Z5FFGJMH9fy8NjO4FZow\r\n38XoyFon9Stf3rKXWvxGfe6GXHm3KmJXAfSC9MR0ULuQaA6tVLClfI0gp/HV\r\nYD+upfO5oj2ybwdZWsmg30M6UmPefeeTHGHtItPO34+w51NTKFJouU/OW3fw\r\nGSsTuyN7f9x50lz5dkjWiIe5PalT3/bPB6YBAt+gZBSJQOBU4owwfmmRbn2H\r\nm/0Ai5CEB3vmpFFcZ4X051f31JXK3tfLs4/BcwRNGzVgYGYC7/cW8oHFTXw6\r\nDp/LToSHI+3Uk2CIrza55mMkofgiKFqtnEgEr2gkqu7pLUgqSAaw+VJgcqNK\r\ngddWbkCGUu0BtU6NwkkGktUcDdWVeSUsKqR6CSQiXoSMJRJNCo6xN2fkFxy/\r\nhbL2k1gMaK1Y4sqodUdNeTcto0H/lY4bUn6AE4vabt1cSRJdyl/DkQRT8mhr\r\nUOGFPoCrV+OIHxKkZVDcpHZRFsgKC+50zHppl/Dd4DNsIM453RVozDqXeEke\r\nXDhzqawvtcFMS29ncG34nzskInaIE2Tl/jg=\r\n=sRD1\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"brettjashford","email":"brettjashford@gmail.com"},"directories":{},"maintainers":[{"name":"brettjashford","email":"brettjashford@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mqtt-subscriptions_1.1.4_1651261773614_0.5255147568054719"},"_hasShrinkwrap":false},"1.1.5":{"name":"@brettjashford/graphql-mqtt-subscriptions","version":"1.1.5","description":"A graphql-subscriptions PubSub Engine using mqtt protocol","publishConfig":{"access":"public"},"main":"dist/index.js","repository":{"type":"git","url":"git+https://github.com/aerogear/graphql-mqtt-subscriptions.git"},"keywords":["graphql","mqtt","apollo","subscriptions"],"author":{"name":"David Yahalomi"},"license":"MIT","bugs":{"url":"https://github.com/aerogear/graphql-mqtt-subscriptions/issues"},"homepage":"https://github.com/aerogear/graphql-mqtt-subscriptions","scripts":{"compile":"tsc --noUnusedParameters --noUnusedLocals","test":"tsc && nyc --reporter=lcov mocha ./dist/test/tests.js","posttest":"npm run lint","lint":"tslint ./src/**/*.ts","watch":"tsc -w","integration":"npm run compile && mocha --reporter spec --full-trace --exit ./dist/test/integration-tests.js ","benchmark":"npm run compile && mocha --reporter spec --full-trace ./dist/test/benchmark.js ","release:prep":"./scripts/prepareRelease.sh","release:validate":"./scripts/validateRelease.sh","release:publish":"./scripts/publishRelease.sh"},"dependencies":{"iterall":"^1.2.2","mqtt":"^4.0.0"},"devDependencies":{"@istanbuljs/nyc-config-typescript":"0.1.3","@types/chai":"4.2.11","@types/chai-as-promised":"7.1.3","@types/graphql":"14.2.3","@types/mocha":"8.0.0","@types/node":"11.13.9","@types/simple-mock":"0.8.1","chai":"4.2.0","chai-as-promised":"7.1.1","coveralls":"3.1.0","graphql":"15.1.0","graphql-subscriptions":"1.1.0","mocha":"8.0.1","nyc":"15.1.0","simple-mock":"0.8.0","tslint":"5.20.1","typescript":"3.9.5"},"peerDependencies":{"graphql-subscriptions":"^1.1.0"},"typings":"dist/index.d.ts","typescript":{"definition":"dist/index.d.ts"},"nyc":{"extends":"@istanbuljs/nyc-config-typescript","all":true,"check-coverage":false,"exclude":["src/test/**/*.ts"]},"readme":"# graphql-mqtt-subscriptions\n\n[![CircleCI](https://circleci.com/gh/aerogear/graphql-mqtt-subscriptions.svg?style=svg)](https://circleci.com/gh/aerogear/graphql-mqtt-subscriptions)\n[![Coverage Status](https://coveralls.io/repos/github/aerogear/graphql-mqtt-subscriptions/badge.svg?branch=master)](https://coveralls.io/github/aerogear/graphql-mqtt-subscriptions?branch=master)\n\nThis package implements the AsyncIterator Interface and PubSubEngine Interface from the [graphql-subscriptions](https://github.com/apollographql/graphql-subscriptions) package. \nIt allows you to connect your subscriptions manager to an MQTT enabled Pub Sub broker to support \nhorizontally scalable subscriptions setup.\nThis package is an adapted version of my [graphql-redis-subscriptions](https://github.com/davidyaha/graphql-redis-subscriptions) package.\n\n## Installation\n\n```\nnpm install graphql-mqtt-subscriptions\n```\n\n## Using the AsyncIterator Interface\n\nDefine your GraphQL schema with a `Subscription` type.\n\n```graphql\nschema {\n  query: Query\n  mutation: Mutation\n  subscription: Subscription\n}\n\ntype Subscription {\n    somethingChanged: Result\n}\n\ntype Result {\n    id: String\n}\n```\n\nNow, create a `MQTTPubSub` instance.\n\n```javascript\nimport { MQTTPubSub } from 'graphql-mqtt-subscriptions';\nconst pubsub = new MQTTPubSub(); // connecting to mqtt://localhost by default\n```\n\nNow, implement the Subscriptions type resolver, using `pubsub.asyncIterator` to map the event you need.\n\n```javascript\nconst SOMETHING_CHANGED_TOPIC = 'something_changed';\n\nexport const resolvers = {\n  Subscription: {\n    somethingChanged: {\n      subscribe: () => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC)\n    }\n  }\n}\n```\n\n> Subscriptions resolvers are not a function, but an object with `subscribe` method, that returns `AsyncIterable`.\n\nThe `AsyncIterator` method will tell the MQTT client to listen for messages from the MQTT broker on the topic provided, and wraps that listener in an `AsyncIterator` object. \n\nWhen messages are received from the topic, those messages can be returned back to connected clients.\n\n`pubsub.publish` can be used to send messages to a given topic.\n\n```js\npubsub.publish(SOMETHING_CHANGED_TOPIC, { somethingChanged: { id: \"123\" }});\n```\n\n## Passing Your Own MQTT Client\n\nThe basic usage allows you to connect to an MQTT broker running on on `localhost` and works well for development.\nFor production usage, it is recommended you pass your own MQTT client.\n \n```javascript\nimport { connect } from 'mqtt';\nimport { MQTTPubSub } from 'graphql-mqtt-subscriptions';\n\nconst client = connect('mqtt://test.mosquitto.org', {\n  reconnectPeriod: 1000,\n});\n\nconst pubsub = new MQTTPubSub({\n  client\n});\n```\n\nYou can learn more on the mqtt options object [here](https://github.com/mqttjs/MQTT.js#client).\n\n## Dynamically Create a Topic Based on Subscription Args Passed on the Query:\n\n```javascript\nexport const resolvers = {\n  Subscription: {\n    somethingChanged: {\n      subscribe: (_, args) => pubsub.asyncIterator(`${SOMETHING_CHANGED_TOPIC}.${args.relevantId}`),\n    },\n  },\n}\n```\n\n## Using Arguments and Payload to Filter Events\n\n```javascript\nimport { withFilter } from 'graphql-subscriptions';\n\nexport const resolvers = {\n  Subscription: {\n    somethingChanged: {\n      subscribe: withFilter(\n        (_, args) => pubsub.asyncIterator(`${SOMETHING_CHANGED_TOPIC}.${args.relevantId}`),\n        (payload, variables) => payload.somethingChanged.id === variables.relevantId,\n      ),\n    },\n  },\n}\n```\n\n## Changing QoS for publications or subscriptions\n\nAs specified [here](https://github.com/mqttjs/MQTT.js#publish), the MQTT.js publish and subscribe functions takes an \noptions object. This object can be defined per trigger with `publishOptions` and `subscribeOptions` resolvers.\n\n```javascript\nconst triggerToQoSMap = {\n  'comments.added': 1,\n  'comments.updated': 2,\n};\n\nconst pubsub = new MQTTPubSub({\n  publishOptions: trigger => Promise.resolve({ qos: triggerToQoSMap[trigger] }),\n  \n  subscribeOptions: (trigger, channelOptions) => Promise.resolve({ \n    qos: Math.max(triggerToQoSMap[trigger], channelOptions.maxQoS), \n  }),\n});\n```\n\n## Get Notified of the Actual QoS Assigned for a Subscription\n\nMQTT allows the broker to assign different QoS levels than the one requested by the client. \nIn order to know what QoS was given to your subscription, you can pass in a callback called `onMQTTSubscribe`\n\n```javascript\nconst onMQTTSubscribe = (subId, granted) => {\n  console.log(`Subscription with id ${subId} was given QoS of ${granted.qos}`);\n}\n\nconst pubsub = new MQTTPubSub({onMQTTSubscribe});\n```\n\n## Change Encoding Used to Encode and Decode Messages\n\nSupported encodings available [here](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) \n\n```javascript\nconst pubsub = new MQTTPubSub({\n  parseMessageWithEncoding: 'utf16le',\n});\n```\n\n\n## Basic Usage with SubscriptionManager (Deprecated)\n\n```javascript\nimport { MQTTPubSub } from 'graphql-mqtt-subscriptions';\nconst pubsub = new MQTTPubSub(); // connecting to mqtt://localhost on default\nconst subscriptionManager = new SubscriptionManager({\n  schema,\n  pubsub,\n  setupFunctions: {},\n});\n```\n\n## Using Trigger Transform (Deprecated)\n\nSimilar to the [graphql-redis-subscriptions](https://github.com/davidyaha/graphql-redis-subscriptions) package, this package supports\na trigger transform function. This trigger transform allows you to use the `channelOptions` object provided to the `SubscriptionManager`\ninstance, and return a trigger string which is more detailed then the regular trigger. \n\nHere is an example of a generic trigger transform.\n\n```javascript\nconst triggerTransform = (trigger, { path }) => [trigger, ...path].join('.');\n```\n\n> Note that a `path` field to be passed to the `channelOptions` but you can do whatever you want.\n\nNext, pass the `triggerTransform` to the `MQTTPubSub` constructor.\n\n```javascript\nconst pubsub = new MQTTPubSub({\n  triggerTransform,\n});\n```\n\nLastly, a setupFunction is provided for the `commentsAdded` subscription field.\nIt specifies one trigger called `comments.added` and it is called with the `channelOptions` object that holds `repoName` path fragment.\n```javascript\nconst subscriptionManager = new SubscriptionManager({\n  schema,\n  setupFunctions: {\n    commentsAdded: (options, { repoName }) => ({\n      'comments/added': {\n        channelOptions: { path: [repoName] },\n      },\n    }),\n  },\n  pubsub,\n});\n```\n> Note that the `triggerTransform` dependency on the `path` field is satisfied here.\n\nWhen `subscribe` is called like this:\n\n```javascript\nconst query = `\n  subscription X($repoName: String!) {\n    commentsAdded(repoName: $repoName)\n  }\n`;\nconst variables = {repoName: 'graphql-mqtt-subscriptions'};\nsubscriptionManager.subscribe({ query, operationName: 'X', variables, callback });\n```\n\nThe subscription string that MQTT will receive will be `comments.added.graphql-mqtt-subscriptions`.\nThis subscription string is much more specific and means the the filtering required for this type of subscription is not needed anymore.\nThis is one step towards lifting the load off of the graphql api server regarding subscriptions.","readmeFilename":"README.md","gitHead":"197e50bd0acef747a4b47ee98e694c8bd62828d8","_id":"@brettjashford/graphql-mqtt-subscriptions@1.1.5","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-JXTxJI6aLteCcRNKc5EVA8cBMiv51DUti2eQ0q0MxuVevECREFrQCD/b/sjfYB2Pyknh2czZXBcNlx46UZmRtg==","shasum":"6d0cc9aa68a999928749ce3162536bdaa7283db6","tarball":"https://registry.npmjs.org/@brettjashford/graphql-mqtt-subscriptions/-/graphql-mqtt-subscriptions-1.1.5.tgz","fileCount":37,"unpackedSize":387236,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDNtWUHb7uYVdJYJA6Drxrny+MCRQAl0hjMtAwBO0EtCAIga3hKjidGdSpRw+0rzO/Z3jGxIU/4WmC6X86Nf+QX0Js="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJibEKuACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqkeQ/+L5cXJA9g3PYceDxJ9zQhqIjeFN1c9pEH/Vp86fawvvLPpu79\r\ngVjZD3NiCWQusp9JQA8SjE0XRXF56bLxQCe62640fX3Zu/2T/T8BOOBp1CYy\r\nPYTP9tgFQmY0gHK1meGY8AXLKMgAxxNDBjjFWTmCAOCBHdK6AEtsy+pSHWsO\r\n0Jy5AmEqXMtgbCQ6Z0/ZzNhRGsCwYlh1SG3k5nJcL/B4xtl0TWMvAGkeSzv7\r\nFJBHmKQg+m3y+UXGvZnDlpzIWHinJbku5qbvqyd4G+zfWMgeLBBT5ClnqeaW\r\nGoQp7pLtMX6rzxThk8eW3/Sa4C+O4c+eV7ovh3WYJh5mk1iC7F9FYzjlI++d\r\nOkS32KZ4biRmrMiHnLsrSgtAPLooCGhTYp9Jzq/ieJ2BMme/Cc9caovzpaPn\r\nhvVa9Pkr513Si8BSDOLZ42bLXXtwYYbMJ2dvpbUrYfcURaFIj4GMYliAAggB\r\nhmsPXWCbBHzRg15GQ+0eoTv47ZmhYjjfhYM30xHr6QPjvFxMbgOIxV26/xpy\r\n43DLb7b5HcJM84lS+1zYhI3m9WW23wUIrXKp8xwp/THmmXxr57vZjIiJS8Y1\r\nGB39/jI3AK0PbOHl0XQCVlYkjRqcbi6VCt4lGO4cZpK10V8KNqxUQhvmPkHs\r\njg5wo4WKvSZMkWivKL29qVwE/tHz/jjaU9s=\r\n=jD/8\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"brettjashford","email":"brettjashford@gmail.com"},"directories":{},"maintainers":[{"name":"brettjashford","email":"brettjashford@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mqtt-subscriptions_1.1.5_1651262126490_0.5583526671724481"},"_hasShrinkwrap":false}},"time":{"created":"2022-04-29T19:49:33.554Z","1.1.4":"2022-04-29T19:49:33.736Z","modified":"2022-04-29T19:55:26.696Z","1.1.5":"2022-04-29T19:55:26.638Z"},"maintainers":[{"name":"brettjashford","email":"brettjashford@gmail.com"}],"description":"A graphql-subscriptions PubSub Engine using mqtt protocol","homepage":"https://github.com/aerogear/graphql-mqtt-subscriptions","keywords":["graphql","mqtt","apollo","subscriptions"],"repository":{"type":"git","url":"https://github.com/aerogear/graphql-mqtt-subscriptions.git"},"author":{"name":"David Yahalomi"},"bugs":{"url":"https://github.com/aerogear/graphql-mqtt-subscriptions/issues"},"license":"MIT","readme":"","readmeFilename":""}