-
-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathpubsub.ts
More file actions
26 lines (23 loc) · 759 Bytes
/
Copy pathpubsub.ts
File metadata and controls
26 lines (23 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { createRedisEventTarget } from "@graphql-yoga/redis-event-target";
import { createPubSub } from "@graphql-yoga/subscription";
import { Redis } from "ioredis";
import { type NewCommentPayload } from "./comment.type";
const redisUrl = process.env.REDIS_URL;
if (!redisUrl) {
throw new Error("REDIS_URL env variable is not defined");
}
export const enum Topic {
NEW_COMMENT = "NEW_COMMENT",
}
export const pubSub = createPubSub<{
[Topic.NEW_COMMENT]: [NewCommentPayload];
}>({
eventTarget: createRedisEventTarget({
publishClient: new Redis(redisUrl, {
retryStrategy: times => Math.max(times * 100, 3000),
}),
subscribeClient: new Redis(redisUrl, {
retryStrategy: times => Math.max(times * 100, 3000),
}),
}),
});