Skip to content

Commit

Permalink
feature: [19] notification schema / resolver 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph0926 committed Sep 11, 2024
1 parent bc4a230 commit 5da933e
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NotificationResolver } from "./notification.resolver";
import { UserResolver } from "./user.resolver";

export const resolvers = [UserResolver];
export const resolvers = [UserResolver, NotificationResolver];
79 changes: 79 additions & 0 deletions server/src/graphql/resolvers/notification.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
createNotificationGroup,
deleteNotificationGroup,
getAllNotificationGroups,
updateNotificationGroup,
} from "@/services/notification.service";
import { AppContextType } from "@/types/common.type";
import { NotificationType } from "@/types/notification.type";
import { authenticateGroupQLRoute } from "@/utils/checkSession.util";

export const NotificationResolver = {
Query: {
async getUserNotificationGroups(
_: undefined,
{ userId }: { userId: string },
contextValue: AppContextType
) {
const { req } = contextValue;
authenticateGroupQLRoute(req);

const notifications = await getAllNotificationGroups(userId);

return {
notifications,
};
},
},

Mutation: {
async createNotificationGroup(
_: undefined,
args: { group: NotificationType },
contextValue: AppContextType
) {
const { req } = contextValue;
authenticateGroupQLRoute(req);

const notification = await createNotificationGroup(args.group);

return {
notifications: [notification],
};
},

async updateNotificationGroup(
_: undefined,
args: { notificationId: string; group: NotificationType },
contextValue: AppContextType
) {
const { req } = contextValue;
const { notificationId, group } = args;
authenticateGroupQLRoute(req);

await updateNotificationGroup(notificationId, group);

const notification = { ...group, id: notificationId };

return {
notifications: [notification],
};
},

async deleteNotificationGroup(
_: undefined,
args: { notificationId: string },
contextValue: AppContextType
) {
const { req } = contextValue;
const { notificationId } = args;
authenticateGroupQLRoute(req);

await deleteNotificationGroup(notificationId);

return {
id: notificationId,
};
},
},
};
6 changes: 5 additions & 1 deletion server/src/graphql/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { mergeTypeDefs } from "@graphql-tools/merge";
import { notificationSchema } from "./notification.schema";
import { userSchema } from "./user.schema";

export const mergedGraphQLSchema = mergeTypeDefs(userSchema);
export const mergedGraphQLSchema = mergeTypeDefs([
userSchema,
notificationSchema,
]);
34 changes: 34 additions & 0 deletions server/src/graphql/schemas/notification.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { buildSchema } from "graphql";

export const notificationSchema = buildSchema(`#graphql
input Notification {
userId: String!
groupName: String!
emails: String!
}
type NotificationResult {
id: ID!
userId: String!
groupName: String!
emails: String!
}
type NotificationResponse {
notifications: [NotificationResult]
}
type DeleteNotificationResponse {
id: ID!
}
type Query {
getUserNotificationGroups(userId: String!): NotificationResponse!
}
type Mutation {
createNotificationGroup(group: Notification!): NotificationResponse!
updateNotificationGroup(notificationId: ID!, group: Notification!): NotificationResponse!
deleteNotificationGroup(notificationId: ID!): DeleteNotificationResponse!
}
`);

0 comments on commit 5da933e

Please sign in to comment.