feat: used new pubsub method to publish
This commit is contained in:
@@ -4,6 +4,7 @@ import { default as Redis, RedisOptions } from 'ioredis';
|
||||
|
||||
import { RedisPubSub } from 'graphql-redis-subscriptions';
|
||||
import { PubSub as LocalPubSub } from 'graphql-subscriptions';
|
||||
import { TopicDef } from './topicsDefs';
|
||||
|
||||
/**
|
||||
* RedisPubSub uses JSON parsing for back and forth conversion, which loses Date objects, hence this reviver brings them back
|
||||
@@ -70,7 +71,7 @@ export class PubSubService implements OnModuleInit {
|
||||
return this.pubsub.asyncIterator(topic, options);
|
||||
}
|
||||
|
||||
async publish(topic: string, payload: any) {
|
||||
async publish<T extends keyof TopicDef>(topic: T, payload: TopicDef[T]) {
|
||||
await this.pubsub.publish(topic, payload);
|
||||
}
|
||||
}
|
||||
|
||||
14
packages/hoppscotch-backend/src/pubsub/topicsDefs.ts
Normal file
14
packages/hoppscotch-backend/src/pubsub/topicsDefs.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { User } from 'src/user/user.model';
|
||||
import { UserEnvironment } from '../user-environment/user-environments.model';
|
||||
|
||||
// A custom message type that defines the topic and the corresponding payload.
|
||||
// For every module that publishes a subscription add its type def and the possible subscription type.
|
||||
export type TopicDef = {
|
||||
[
|
||||
topic: `user_environment/${string}/${'created' | 'updated' | 'deleted'}`
|
||||
]: UserEnvironment;
|
||||
[
|
||||
topic: `user/${string}/${'created' | 'updated' | 'deleted'}`
|
||||
]: User;
|
||||
[topic: `user_environment/${string}/deleted_many`]: number;
|
||||
};
|
||||
Reference in New Issue
Block a user