fix wrong logic uploaded file
This commit is contained in:
@@ -8,7 +8,8 @@ import {
|
||||
import { Builder, SchemaContext } from '../Graphql/graphql.builder'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
import { Message, MessageContextType, MessageType } from '@prisma/client'
|
||||
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
|
||||
import { DateTimeUtils } from '../common/utils/datetime.utils'
|
||||
import { PubSubEvent } from '../common/pubsub/pubsub-event'
|
||||
|
||||
@Injectable()
|
||||
export class MessageSchema extends PothosSchema {
|
||||
@@ -106,37 +107,6 @@ export class MessageSchema extends PothosSchema {
|
||||
|
||||
// mutations
|
||||
this.builder.mutationFields((t) => ({
|
||||
testSendMessage: t.field({
|
||||
type: this.message(),
|
||||
description: 'Test sending a message.',
|
||||
resolve: async (_root, _args, ctx) => {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
ctx.http.pubSub.publish('MESSAGE_SENT', {
|
||||
id: '1',
|
||||
senderId: '1',
|
||||
recipientId: '2',
|
||||
chatRoomId: 'b86e840f-81d3-4043-b57a-f9adf719423c',
|
||||
type: MessageType.TEXT,
|
||||
content: 'Hello, world!',
|
||||
context: MessageContextType.CHAT,
|
||||
metadata: {},
|
||||
sentAt: DateTimeUtils.now().toJSDate(),
|
||||
})
|
||||
return {
|
||||
id: '1',
|
||||
senderId: '1',
|
||||
recipientId: '2',
|
||||
chatRoomId: 'b86e840f-81d3-4043-b57a-f9adf719423c',
|
||||
type: MessageType.TEXT,
|
||||
content: 'Hello, world!',
|
||||
context: MessageContextType.CHAT,
|
||||
metadata: {},
|
||||
sentAt: DateTimeUtils.now().toJSDate(),
|
||||
}
|
||||
},
|
||||
}),
|
||||
sendMessage: t.prismaField({
|
||||
type: this.message(),
|
||||
description: 'Send a message to a chat room.',
|
||||
@@ -182,7 +152,10 @@ export class MessageSchema extends PothosSchema {
|
||||
...query,
|
||||
data: args.input,
|
||||
})
|
||||
ctx.http.pubSub.publish(`MESSAGE_SENT_${message.chatRoomId}`, message)
|
||||
ctx.http.pubSub.publish(
|
||||
`${PubSubEvent.MESSAGE_SENT}.${message.chatRoomId}`,
|
||||
message,
|
||||
)
|
||||
return message
|
||||
},
|
||||
}),
|
||||
@@ -204,7 +177,7 @@ export class MessageSchema extends PothosSchema {
|
||||
websocket: { pubSub },
|
||||
} = ctx
|
||||
return pubSub.asyncIterator(
|
||||
`MESSAGE_SENT_${args.chatRoomId}`,
|
||||
`${PubSubEvent.MESSAGE_SENT}.${args.chatRoomId}`,
|
||||
) as unknown as AsyncIterable<Message>
|
||||
},
|
||||
resolve: (payload: Message) => payload,
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
Reference in New Issue
Block a user