sdy

create sendMessage(subscribe)

1 type Subscription { 1 type Subscription {
2 - sendMessage(message: String!): Message! 2 + sendMessage: Message
3 } 3 }
......
1 -import { prisma } from "../../../utils"; 1 +import { isAuthenticated, prisma } from "../../../utils";
2 +import { NEW_MESSAGE_TOPIC } from "../../../topics";
2 3
3 export default { 4 export default {
4 Subscription: { 5 Subscription: {
5 - sendMessage: async (_, args) => { 6 + sendMessage: {
6 - const { message } = args; 7 + subscribe: async (_, __, { request, pubsub }) => {
8 + pubsub.asyncIterator(NEW_MESSAGE_TOPIC);
9 + },
7 }, 10 },
8 }, 11 },
9 }; 12 };
......