sdy

update addCategory

1 -import { prisma } from "../../../utils"; 1 +import { prisma, isAuthenticated } from "../../../utils";
2 +import { NEW_CATEGORY } from "../../../topics";
2 3
3 export default { 4 export default {
4 Mutation: { 5 Mutation: {
5 - addCategory: async (_, args) => { 6 + addCategory: async (_, args, { request, pubsub }) => {
7 + isAuthenticated(request);
6 const { name } = args; 8 const { name } = args;
7 const newCategory = await prisma.category.create({ 9 const newCategory = await prisma.category.create({
8 data: { 10 data: {
9 name, 11 name,
10 }, 12 },
11 }); 13 });
14 + if (newCategory !== undefined) {
15 + pubsub.publish(NEW_CATEGORY, { subCategory: newCategory });
16 + }
12 return newCategory; 17 return newCategory;
13 }, 18 },
14 }, 19 },
......