-
Notifications
You must be signed in to change notification settings - Fork 131
Using an external PubSub engine #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Basically, you can implement any custom You can implement your own logic and transform your MQTT subscription into an
import { $$asyncIterator } from 'iterall';
const redisClient = createClient({ host, port, password });
const redisEventToAsyncIterator = (redisClient: RedisClient, eventName: string) => {
let promiseResolve;
redisClient.on('message', (channel: string, message: string) => {
const parsedMessage = JSON.parse(message);
if (promiseResolve && eventName === channel) {
promiseResolve(parsedMessage);
}
});
return {
next() {
return new Promise(resolve => {
promiseResolve = resolve;
}).then(value => ({
done: false,
value,
}));
},
return() {
return Promise.resolve({ done: true, value: undefined });
},
throw(e: Error) {
return Promise.reject(e);
},
[$$asyncIterator]() {
return this;
},
};
}; Then, you can use it as your subscriptions stream, in your resolver: const REDIS_EVENT_NAME = 'something_changed';
const resolvers = {
Subscription: {
somethingChanged: {
subscribe: () => redisEventToAsyncIterator(client, REDIS_EVENT_NAME),
}
}
} And then each time your Redis instance publishes a message - it will map this message to your GraphQL subscription. You can see more implementations of
The |
@dotansimha Thank you very much, I'm going to try that. |
@emmanuelvacher did you managed to implement your own |
@dotansimha yes I managed to implement my own |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I would like to know if it is possible to use
graphql-mqtt-subscriptions
along with this package. More precisely, I'd like someone to explain how to wrap a pubsub with anAsyncIterator
since the apollo client needs one for the subscription to be effective.My final goal is to use a MQTT broker to handle subscriptions instead of the in-memory pubsub engine provided by your package.
Thank you for your help.
The text was updated successfully, but these errors were encountered: