We are using GraphQL Subscriptions and pubsub to subscribe to posts.
When more than 10 subscriptions occur we get the the node warning "MaxListenersExceededWarning: Possible EventEmitter memory leak detected."
Is it possible to raise the max listeners in the pubsub class?
The pubsub class is inside a separate module and looks like this:
import { PubSub } from 'graphql-subscriptions';
const pubsub = new PubSub();
export { pubsub };
The subscription server looks like this:
import { SubscriptionManager } from 'graphql-subscriptions';
import { createServer } from 'http';
import { SubscriptionServer } from 'subscriptions-transport-ws';
import { pubsub } from './subscriptions';
import executableSchema from './executableSchema';
const WS_PORT = 8080;
const websocketServer = createServer((request, response) => {
response.writeHead(404);
response.end();
});
websocketServer.listen(WS_PORT, () => console.log(
`Websocket Server is now running on http://localhost:${WS_PORT}`
));
const subscriptionManager = new SubscriptionManager({
schema: executableSchema,
pubsub: pubsub,
setupFunctions: {
newPost: (options, args) => {
return {
newPostChannel: {
filter: (post) => {
return args.publicationId === post.relatedPublication.id;
}
},
};
},
},
});
const subscriptionServer = new SubscriptionServer({
subscriptionManager: subscriptionManager
}, {
server: websocketServer,
path: '/',
});
export {
subscriptionServer,
};