chore: updated types to def and changed deleted many as a new indexed type
This commit is contained in:
@@ -4,7 +4,7 @@ import { default as Redis, RedisOptions } from 'ioredis';
|
|||||||
|
|
||||||
import { RedisPubSub } from 'graphql-redis-subscriptions';
|
import { RedisPubSub } from 'graphql-redis-subscriptions';
|
||||||
import { PubSub as LocalPubSub } from 'graphql-subscriptions';
|
import { PubSub as LocalPubSub } from 'graphql-subscriptions';
|
||||||
import { MessageType } from './subscriptionTopicsDefs';
|
import { TopicDef } from './subscriptionTopicsDefs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RedisPubSub uses JSON parsing for back and forth conversion, which loses Date objects, hence this reviver brings them back
|
* RedisPubSub uses JSON parsing for back and forth conversion, which loses Date objects, hence this reviver brings them back
|
||||||
@@ -71,10 +71,7 @@ export class PubSubService implements OnModuleInit {
|
|||||||
return this.pubsub.asyncIterator(topic, options);
|
return this.pubsub.asyncIterator(topic, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async publish<T extends keyof MessageType>(
|
async publish<T extends keyof TopicDef>(topic: T, payload: TopicDef[T]) {
|
||||||
topic: T,
|
|
||||||
payload: MessageType[T],
|
|
||||||
) {
|
|
||||||
await this.pubsub.publish(topic, payload);
|
await this.pubsub.publish(topic, payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { UserEnvironment } from '../user-environment/user-environments.model';
|
import { UserEnvironment } from '../user-environment/user-environments.model';
|
||||||
import { PrimitiveTypes } from '../types/primitiveTypes';
|
|
||||||
|
|
||||||
// A custom message type that defines the topic and the corresponding payload.
|
// 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.
|
// For every module that publishes a subscription add its type def and the possible subscription type.
|
||||||
export type MessageType = {
|
export type TopicDef = {
|
||||||
[
|
[
|
||||||
topic: `user_environment/${string}/${
|
topic: `user_environment/${string}/${'created' | 'updated' | 'deleted'}`
|
||||||
| 'created'
|
]: UserEnvironment;
|
||||||
| 'updated'
|
[topic: `user_environment/${string}/deleted_many`]: number;
|
||||||
| 'deleted'
|
|
||||||
| 'deleted_many'}`
|
|
||||||
]: UserEnvironment | PrimitiveTypes; // Returning a number hence having a union with `PrimitiveTypes`.
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user