update service status

This commit is contained in:
2024-10-23 15:43:50 +07:00
parent 7e55f4093b
commit 2872ac69ef
14 changed files with 212 additions and 32 deletions

View File

@@ -79,18 +79,66 @@ export class MessageSchema extends PothosSchema {
});
},
}),
messagesByChatRoomId: t.prismaField({
type: [this.message()],
description: 'Retrieve a list of messages by chat room ID.',
args: this.builder.generator.findManyArgs('Message'),
resolve: async (query, root, args) => {
return await this.prisma.message.findMany({
...query,
where: args.filter ?? undefined,
});
},
}),
}));
// mutations
this.builder.mutationFields((t) => ({
sendMessage: t.prismaField({
type: this.message(),
description: 'Send a message to a chat room.',
args: {
input: t.arg({
type: this.builder.generator.getCreateInput('Message'),
description: 'The message to send.',
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
const message = await this.prisma.message.create({
...query,
data: args.input,
});
ctx.pubSub.publish('MESSAGE_SENT', message);
return message;
},
}),
}));
// subscriptions
// this.builder.subscriptionFields((t) => ({
// messageSent: t.field({
// subscribe: (_parent, _args, ctx) => {
// return ctx.pubSub.asyncIterator('MESSAGE_SENT');
// },
// resolve: (payload) => payload as any,
// }),
// }));
/* The code snippet `subscriptions` is currently commented out in the provided TypeScript class. It
appears to be a placeholder or a section where subscription-related logic or fields could be
defined. In GraphQL, subscriptions are used to listen for real-time events or changes in data
and receive updates when those events occur. */
this.builder.subscriptionFields((t) => ({
messageSent: t.field({
subscribe: (_, __, ctx) => {
return {
[Symbol.asyncIterator]: () =>
ctx.pubSub.asyncIterator('MESSAGE_SENT'),
};
},
type: this.message(), // Add the type property
resolve: (payload) =>
payload as {
message: 'Json';
id: string;
senderId: string;
chatRoomId: string;
sentAt: Date;
},
}),
}));
}
}