sdy

add pubsub

1 import { prisma, isAuthenticated } from "../../../utils"; 1 import { prisma, isAuthenticated } from "../../../utils";
2 +import { NEW_MESSAGE } from "../../../topics";
2 3
3 export default { 4 export default {
4 Mutation: { 5 Mutation: {
5 - createMessage: async (_, args, { request }) => { 6 + createMessage: async (_, args, { request, pubsub }) => {
6 isAuthenticated(request); 7 isAuthenticated(request);
7 const { user } = request; 8 const { user } = request;
8 const { message, roomId } = args; 9 const { message, roomId } = args;
...@@ -46,6 +47,11 @@ export default { ...@@ -46,6 +47,11 @@ export default {
46 } else { 47 } else {
47 throw new Error("There is no room"); 48 throw new Error("There is no room");
48 } 49 }
50 +
51 + if (messageObj !== undefined) {
52 + pubsub.publish(NEW_MESSAGE, { subMessage: messageObj });
53 + }
54 +
49 return messageObj; 55 return messageObj;
50 }, 56 },
51 }, 57 },
......