* 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
29 lines
747 B
TypeScript
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);
|
|
}
|
|
}
|