chore: refactor pub/sub iterator usage across schema files
- Updated pub/sub iterator methods from `asyncIterableIterator` to `asyncIterator` in multiple schema files for improved compatibility with the latest GraphQL subscriptions. - Refactored subscription logic in CollaborationSession, Document, Message, User, and other schema files to enhance readability and maintainability. - Adjusted imports in GraphQL builder to utilize RedisPubSub for better performance in subscription handling.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { clerkClient } from '@clerk/express'
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common'
|
||||
import { ChatRoom, Message, MessageContextType, MessageType, Role } from '@prisma/client'
|
||||
import { Message, Role } from '@prisma/client'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import { ChatroomSchema } from '../ChatRoom/chatroom.schema'
|
||||
import { Builder, SchemaContext } from '../Graphql/graphql.builder'
|
||||
@@ -547,17 +547,15 @@ export class UserSchema extends PothosSchema {
|
||||
this.builder.subscriptionFields((t) => ({
|
||||
userScopedMessage: t.field({
|
||||
type: this.messageSchema.message(),
|
||||
subscribe: async (_, _args, ctx: SchemaContext) => {
|
||||
subscribe: async (_, _args, ctx) => {
|
||||
if (!ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
const {
|
||||
websocket: { pubSub },
|
||||
} = ctx
|
||||
return pubSub.asyncIterableIterator([
|
||||
|
||||
return ctx.websocket.pubSub.asyncIterator([
|
||||
`${PubSubEvent.NEW_MESSAGE}.${ctx.websocket.me?.id}`,
|
||||
`${PubSubEvent.NOTIFICATION}.${ctx.websocket.me?.id}`,
|
||||
])
|
||||
]) as unknown as AsyncIterable<Message>
|
||||
},
|
||||
resolve: async (payload: Message) => payload,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user