-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: [19] notification schema / resolver 구현
- Loading branch information
1 parent
bc4a230
commit 5da933e
Showing
4 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
} | ||
`); |