{"_id":"@aerogear/graphql-mqtt-subscriptions","_rev":"8-a3ff429579c02cb39b1569c80e9e18ac","name":"@aerogear/graphql-mqtt-subscriptions","dist-tags":{"latest":"1.1.3"},"versions":{"1.1.1":{"name":"@aerogear/graphql-mqtt-subscriptions","version":"1.1.1","description":"A graphql-subscriptions PubSub Engine using mqtt protocol","publishConfig":{"access":"public"},"main":"dist/index.js","repository":{"type":"git","url":"git+https://github.com/davidyaha/graphql-mqtt-subscriptions.git"},"keywords":["graphql","mqtt","apollo","subscriptions"],"author":{"name":"David Yahalomi"},"license":"MIT","bugs":{"url":"https://github.com/davidyaha/graphql-mqtt-subscriptions/issues"},"homepage":"https://github.com/davidyaha/graphql-mqtt-subscriptions","scripts":{"compile":"tsc --noUnusedParameters --noUnusedLocals","pretest":"npm run compile","test":"npm run testonly --","posttest":"npm run lint","lint":"tslint ./src/**/*.ts","watch":"tsc -w","testonly":"mocha --reporter spec --full-trace ./dist/test/tests.js ","integration":"npm run compile && mocha --reporter spec --full-trace ./dist/test/integration-tests.js ","benchmark":"npm run compile && mocha --reporter spec --full-trace ./dist/test/benchmark.js ","coverage":"node ./node_modules/istanbul/lib/cli.js cover _mocha -- --full-trace ./dist/test/tests.js","postcoverage":"remap-istanbul --input coverage/coverage.raw.json --type lcovonly --output coverage/lcov.info","prepublish":"npm run test","release:prep":"./scripts/prepareRelease.sh","release:validate":"./scripts/validateRelease.sh","publish":"./scripts/publishRelease.sh"},"dependencies":{"graphql-subscriptions":"^0.4.2","iterall":"^1.1.1","mqtt":"^2.3.0"},"devDependencies":{"@types/chai":"^3.4.34","@types/chai-as-promised":"0.0.30","@types/graphql":"^0.9.0","@types/mocha":"^2.2.33","@types/node":"7.0.18","@types/simple-mock":"0.0.27","chai":"^3.5.0","chai-as-promised":"^6.0.0","coveralls":"^3.0.3","graphql":"^0.10.1","istanbul":"1.0.0-alpha.2","mocha":"^3.0.0","remap-istanbul":"^0.9.5","simple-mock":"^0.7.0","tslint":"^5.2.0","typescript":"^2.3.4"},"typings":"dist/index.d.ts","typescript":{"definition":"dist/index.d.ts"},"gitHead":"6d6e943771306323a28b69ef77138b8cf72f6039","_id":"@aerogear/graphql-mqtt-subscriptions@1.1.1","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"aerogear-ci","email":"aerogear@redhat.com"},"dist":{"integrity":"sha512-enodROaL4mc3VFsAonjsXzrjqBB2s+X4hLnqIy5ua/gcigZGsAUkmBAxBGNnx7+H0zNbfQf8paXNlL/LMaQrhQ==","shasum":"3a59f5aa2e7fbcab2bd8db40a23a802bd08e0a48","tarball":"https://registry.npmjs.org/@aerogear/graphql-mqtt-subscriptions/-/graphql-mqtt-subscriptions-1.1.1.tgz","fileCount":23,"unpackedSize":173417,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcyxKeCRA9TVsSAnZWagAAEAQQAJsx+lXMG+ask/isn6nn\ngJi3jflI1UTCK6Xx9VupscFbCDk0R5j2Pr27vO2kXuyLwx1ovBFmLwgjGofg\nnLfD37YkFrAT83/s68b8kAU0kdbFtPxloaxiOPvpJmvA0JleKVwSFi7tnSOy\nTJpjy2E7dXDPbcdUy9dSf3oGkjJbSYFv0UMu7WLzCsjigUTW4Uo74K7LiMCG\nzH21bBMceQHh6YHlkVtCO6AhJaF8IqJldqjuO8vGZKPVBq5IKeiLtDs7TFFW\nvQikkcV1q2pMVgJCCMygddaaqJivsO6Tqs5fgKhCryjcpNai/dQ6Q4hbRzp/\nJF7VR8yF5nzRq0MBc6KoQySSluPW21Vp7PKQJl40GkWQnV18muLWh4m4c+85\nRo2UVbGy1Qi0OHj691ZmqPepVrckNmiY1O4zIsa9UlHnPPO5l3bJUWcAUhxY\n4MrnA1QY6iP1foj1WxBpJRn4MD3AHVx1LLJy77rmH2xGOROjgLq/AZO63H9y\nhTOR3CDaq1IR5L+nErHN7rE9d9Gs21vbpjWGzKReAIniBce0qxRstqbEkDPe\nKwlc2nFHeVhstn6oKh0Ww8rOYXzHjsbe3eeUjU08ocP5x5poF9+DZaPJT/6J\nd9YDM9pbUdOt5kk2L6UAy8//FY6Wjk0bO+DTcJ7K9gmiuGud6vCvlEZR4arx\nOSd5\r\n=yZc7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGIvFavIBKen3sN5lg+FM5GpL1yVOdLmQaSqzdCFIPuAAiEA3RpTmri1LRqTP7aP+NAb4icDwn+N9zeGAoHHZXaGZZU="}]},"maintainers":[{"name":"darahayes","email":"dara.s.hayes@gmail.com"},{"name":"aerogears","email":"aerogear@redhat.com"},{"name":"danielpassos","email":"daniel@passos.me"},{"name":"lrossetti","email":"leonardo@goldark.com.br"},{"name":"aliok","email":"aliok@apache.org"},{"name":"wtrocki","email":"wtrocki@redhat.com"},{"name":"matzew","email":"matzew@apache.org"},{"name":"scoady","email":"scoady@redhat.com"},{"name":"aerogear-ci","email":"aerogear@redhat.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mqtt-subscriptions_1.1.1_1556812445856_0.5168774565822307"},"_hasShrinkwrap":false},"1.1.2":{"name":"@aerogear/graphql-mqtt-subscriptions","version":"1.1.2","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","pretest":"npm run compile","test":"npm run testonly --","posttest":"npm run lint","lint":"tslint ./src/**/*.ts","watch":"tsc -w","testonly":"mocha --reporter spec --full-trace ./dist/test/tests.js ","integration":"npm run compile && mocha --reporter spec --full-trace ./dist/test/integration-tests.js ","benchmark":"npm run compile && mocha --reporter spec --full-trace ./dist/test/benchmark.js ","coverage":"node ./node_modules/istanbul/lib/cli.js cover _mocha -- --full-trace ./dist/test/tests.js","postcoverage":"remap-istanbul --input coverage/coverage.raw.json --type lcovonly --output coverage/lcov.info","prepublish":"npm run test","release:prep":"./scripts/prepareRelease.sh","release:validate":"./scripts/validateRelease.sh","publish":"./scripts/publishRelease.sh"},"dependencies":{"graphql-subscriptions":"^0.4.2","iterall":"^1.1.1","mqtt":"^2.3.0"},"devDependencies":{"@types/chai":"^3.4.34","@types/chai-as-promised":"0.0.30","@types/graphql":"^0.9.0","@types/mocha":"^2.2.33","@types/node":"7.0.18","@types/simple-mock":"0.0.27","chai":"^3.5.0","chai-as-promised":"^6.0.0","coveralls":"^3.0.3","graphql":"^0.10.1","istanbul":"1.0.0-alpha.2","mocha":"^3.0.0","remap-istanbul":"^0.9.5","simple-mock":"^0.7.0","tslint":"^5.2.0","typescript":"^2.3.4"},"typings":"dist/index.d.ts","typescript":{"definition":"dist/index.d.ts"},"gitHead":"a68ad41b799fde49e917812e0541391323a3f0a8","_id":"@aerogear/graphql-mqtt-subscriptions@1.1.2","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"aerogear-ci","email":"aerogear@redhat.com"},"dist":{"integrity":"sha512-uq8pzQq1h3utnMXwjQKD+hIJHg/m3wM1Krxas7fPYw62GtF/A2gcVwcTZd5SXXZPqzd3loZm/pN+FBffI5MDew==","shasum":"7003478edb0253b5c822afab8c6541ed2d23fdcb","tarball":"https://registry.npmjs.org/@aerogear/graphql-mqtt-subscriptions/-/graphql-mqtt-subscriptions-1.1.2.tgz","fileCount":23,"unpackedSize":173414,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcyxQ/CRA9TVsSAnZWagAA54cP/3IF/IPCmN3G9oNB9mP8\nMz6xmt5qHI8Q+iZYdvd2j2iiEsGTauQb+wBXa+igTysCoTe81DWmB97sl6nV\n5UFwfLKXRKj2vEnNCwN0mtyRbzAnQcE8ls+aop9BCCbRPgLGRRdnjZDp0o3e\n39Im39mz1331JreP/cncjJPugSNiG9MQv04SBITjxgJnK2SJQMHVSH/clrTm\nEleaL/pvgwAZgdXEdf8vJMTwwrL8PZeOllrJNbfTL7PjD55WvY8hnieaWMl4\nxdR7xi25mSMi5kPWoh5HoA+u9+lhmnraUS6YusTxOGmUe4PvOo5NkDn5YhRF\nMfdW1UHZBpRpOzC9jSVCoswvAiMQG9oJd1JhiGy6pKf3sjFw8zmon7O28PVq\nkmd+99MmiWuVmCVFf4ddKJxsBnbO3NzFl1xXwuY8KqIsTreXDe2RlYtdW8An\nffI/+YSrzFtzUWsCwpLL0HgxrZ9nT5TxtDxehVcxWmRDna7AKLSr/GofkXY0\nA0aYQK9dr0UbjgTbvrIfRS7W2CzwJpHKA4dptTlO5mt42uTyMs3cwRB2wBF+\ncEsKKZHjI4kCyLfHtWBCfNjbyRLeYhGQWNQ6lOPCaZd8WKVYhTY0mmJ6SSQT\ntDj+ZiLXQF9V4lv3RaVsZh9kzXNzJuicwRqI9ngkKJ6yGYyw9YnVlRjKq7AT\nDmY5\r\n=yPHU\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF3upmUXcR5thaJxpgW+C45rckRGUtZhX1bVr9agA7/5AiBKkWTFobRMw9pGHD9ufBsePhLLMks9dR784h+t97B2/w=="}]},"maintainers":[{"name":"aerogear-ci","email":"aerogear@redhat.com"},{"name":"aerogears","email":"aerogear@redhat.com"},{"name":"aliok","email":"aliok@apache.org"},{"name":"danielpassos","email":"daniel@passos.me"},{"name":"darahayes","email":"dara.s.hayes@gmail.com"},{"name":"lrossetti","email":"leonardo@goldark.com.br"},{"name":"matzew","email":"matzew@apache.org"},{"name":"scoady","email":"scoady@redhat.com"},{"name":"wtrocki","email":"wtrocki@redhat.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mqtt-subscriptions_1.1.2_1556812862594_0.847247018124065"},"_hasShrinkwrap":false},"1.1.3":{"name":"@aerogear/graphql-mqtt-subscriptions","version":"1.1.3","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 ./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":"^2.18.8"},"devDependencies":{"@istanbuljs/nyc-config-typescript":"^0.1.3","@types/chai":"^4.1.7","@types/chai-as-promised":"7.1.0","@types/graphql":"^14.2.0","@types/mocha":"^5.2.6","@types/node":"11.13.9","@types/simple-mock":"0.8.0","chai":"^4.2.0","chai-as-promised":"^7.1.1","coveralls":"^3.0.3","graphql":"^14.2.1","graphql-subscriptions":"^1.1.0","mocha":"^6.1.4","nyc":"^14.1.0","simple-mock":"^0.8.0","tslint":"^5.16.0","typescript":"^3.4.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":true},"gitHead":"b1337da4a9d428a9b3303814fcc68fdfa01960cd","_id":"@aerogear/graphql-mqtt-subscriptions@1.1.3","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"aerogear-ci","email":"aerogear@redhat.com"},"dist":{"integrity":"sha512-UDolOQUK3Zw2+n9R4AzscSillfDmsiHw74nkzA78U52cxQtsUCvONvUw51xhUmVdd4br05h0GOJU95E9kRai8g==","shasum":"05048ac0f5f14bb036b9e176cdc9c9d66b6579c5","tarball":"https://registry.npmjs.org/@aerogear/graphql-mqtt-subscriptions/-/graphql-mqtt-subscriptions-1.1.3.tgz","fileCount":38,"unpackedSize":309604,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJczCVWCRA9TVsSAnZWagAAwggQAJXPazB9mC5vREjoWYEx\nASyV+qfhoADrYHBctgjtX0Qft4RA5mBY7d0jSrwO/Xej8rwOsN8mW64BGk9W\nWyQWcXBEDWbtx0VgsFxq4QRz0ZVe3mHc9V6DFmNomRbtGW7+fDSZq4Vi8W8R\ny/bMWH2/ydljXoOMDGkDD1GEv0faZAZ4caPq6LKkMCLbQuGeAqYldMNsHDVP\nq4YqwQZKWwuB5pzZ/uNuj2O/adxxpijMiq1kgfVMXDgc5P5J7nhycNBerc9v\ns4ND4HI7R8cGekOHuQ4k97sZYOo7T30mlTUJTniH+AYnVZAr2x/ZGd2oRNCs\n3hCsA61HQRduHQeOL4MeCOCIGSY2bUk9qfR06H/J3uROUSg2HVYK97SKMCOV\nWrFRl1XswbegexFh4C6WP268NA3QEXrL1it7jrVKfiVz62zNt1U5d1L0n/3L\npDweCtsqoD3AnhciJbK8O6xY0MIXEu7NkQGa1++1gd2Czklicicbm+atA5wA\n+dUE/AXYqoX6JZBaOzBAokwTLBwgSI98X29u4/sroWYt0blrbnERUAHDgFBM\ntPOYdhheek/3Jqh6TU51EOSl/oPKlRCt84fvhIy3vfBgeoHqwHDBZpC2b4Cl\nk8WuDQ/aHiayDwx5BMsrCmMgkddX61F1COS83FFx4RFpj50bloE6PwxsbZF5\nHxCU\r\n=361u\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCjakfF2FN9ppzCfaMdD4TstlkQitZTCZvLj+K3xKBCQQIhAN+UYstI3bi5HXc5n06bvLprq0FtsK6jeJj0s2beyJPy"}]},"maintainers":[{"name":"aerogear-ci","email":"aerogear@redhat.com"},{"name":"aerogears","email":"aerogear@redhat.com"},{"name":"aliok","email":"aliok@apache.org"},{"name":"danielpassos","email":"daniel@passos.me"},{"name":"darahayes","email":"dara.s.hayes@gmail.com"},{"name":"lrossetti","email":"leonardo@goldark.com.br"},{"name":"matzew","email":"matzew@apache.org"},{"name":"scoady","email":"scoady@redhat.com"},{"name":"wtrocki","email":"wtrocki@redhat.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mqtt-subscriptions_1.1.3_1556882773683_0.9018592686980127"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-02T15:54:05.797Z","1.1.1":"2019-05-02T15:54:05.967Z","modified":"2022-06-15T15:07:26.029Z","1.1.2":"2019-05-02T16:01:02.753Z","1.1.3":"2019-05-03T11:26:13.809Z"},"maintainers":[{"email":"aerogear@redhat.com","name":"aerogears"},{"email":"wtrocki@redhat.com","name":"wtrocki"},{"email":"matzew@apache.org","name":"matzew"},{"email":"mziccard@redhat.com","name":"aerogear-ci"},{"email":"massimiliano.ziccardi@gmail.com","name":"ziccardi"},{"email":"ephelan@redhat.com","name":"ephelan"}],"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":"git+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":"# 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## 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## Passing your own client object\n\nThe basic usage is great for development and you will be able to connect to any mqtt enabled server running on your system seamlessly.\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## 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"}