Files
hoppscotch/packages/hoppscotch-backend/src/pubsub/pubsub.service.ts
Balu Babu 3df0492275 refactor: removing Redis from pubsub in sh-backend (HBE-178) (#49)
* chore: removed production env check and redis as pubsub provider in pubsub module

* chore: removed pnpm-lock.yaml file from backend

* chore: removed migrations folder from prisma

* chore: removed RedisPubSub from pubsub service file and changed signature of asyncIterator method
2023-03-21 16:46:54 +05:30

29 lines
747 B
TypeScript

import { OnModuleInit } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { PubSub as LocalPubSub } from 'graphql-subscriptions';
import { TopicDef } from './topicsDefs';
/*
* Figure out which PubSub to use (simple/local for dev and Redis for production)
* and expose it
*/
@Injectable()
export class PubSubService implements OnModuleInit {
private pubsub: LocalPubSub;
onModuleInit() {
console.log('Initialize PubSub');
this.pubsub = new LocalPubSub();
}
asyncIterator<T>(topic: string | string[]): AsyncIterator<T> {
return this.pubsub.asyncIterator(topic);
}
async publish<T extends keyof TopicDef>(topic: T, payload: TopicDef[T]) {
await this.pubsub.publish(topic, payload);
}
}