|
1 |
| -import { makeExecutableSchema, gql } from "apollo-server-express"; |
2 |
| -import { applyMiddleware } from "graphql-middleware"; |
| 1 | +import { makeExecutableSchema } from "apollo-server-express"; |
3 | 2 | import { merge } from "lodash";
|
| 3 | +// import { applyMiddleware } from "graphql-middleware"; |
| 4 | + |
4 | 5 | import {
|
5 | 6 | typeDefs as scalarTypeDefs,
|
6 | 7 | resolvers as scalarResolvers,
|
7 | 8 | } from "graphql-scalars";
|
8 | 9 |
|
9 |
| -// import { UserType } from "../prisma"; |
10 |
| -// import { |
11 |
| -// isAuthorizedByEmail, |
12 |
| -// isAuthorizedByUserType, |
13 |
| -// isAuthorizedByUserId, |
14 |
| -// } from "../middlewares/auth"; |
15 |
| -import authResolvers from "./resolvers/authResolvers"; |
16 |
| -import authType from "./types/authType"; |
17 |
| -import notificationResolvers from "./resolvers/notificationResolvers"; |
18 |
| -import notificationType from "./types/notificationType"; |
19 |
| -import staffResolvers from "./resolvers/staffResolver"; |
20 |
| -import staffType from "./types/staffType"; |
21 |
| -import residentResolvers from "./resolvers/residentResolvers"; |
22 |
| -import residentType from "./types/residentType"; |
23 |
| -import taskResolvers from "./resolvers/taskResolvers"; |
24 |
| -import taskType from "./types/taskType"; |
25 |
| -import warningResolvers from "./resolvers/warningResolvers"; |
26 |
| -import warningType from "./types/warningType"; |
27 |
| - |
28 |
| -const query = gql` |
29 |
| - type Query { |
30 |
| - _empty: String |
31 |
| - } |
32 |
| -`; |
| 10 | +import dataModels from "./types/models"; |
| 11 | +import customTypes from "./types/enums"; |
| 12 | +import resolverTypes from "./types/resolvers"; |
33 | 13 |
|
34 |
| -const mutation = gql` |
35 |
| - type Mutation { |
36 |
| - _empty: String |
37 |
| - } |
38 |
| -`; |
| 14 | +import participantResolvers from "./resolvers/participantResolver"; |
| 15 | +import miscResolvers from "./resolvers/miscResolver"; |
39 | 16 |
|
40 |
| -const executableSchema = makeExecutableSchema({ |
41 |
| - typeDefs: [ |
42 |
| - ...scalarTypeDefs, |
43 |
| - query, |
44 |
| - mutation, |
45 |
| - authType, |
46 |
| - notificationType, |
47 |
| - staffType, |
48 |
| - residentType, |
49 |
| - taskType, |
50 |
| - warningType, |
51 |
| - ], |
52 |
| - resolvers: merge( |
53 |
| - scalarResolvers, |
54 |
| - authResolvers, |
55 |
| - notificationResolvers, |
56 |
| - staffResolvers, |
57 |
| - residentResolvers, |
58 |
| - taskResolvers, |
59 |
| - warningResolvers, |
60 |
| - ), |
| 17 | +const schema = makeExecutableSchema({ |
| 18 | + typeDefs: [...scalarTypeDefs, dataModels, customTypes, resolverTypes], |
| 19 | + resolvers: merge(scalarResolvers, participantResolvers, miscResolvers), |
61 | 20 | });
|
62 | 21 |
|
| 22 | +export default schema; |
| 23 | + |
63 | 24 | // const authorizedByAllUserTypes = () =>
|
64 | 25 | // isAuthorizedByUserType(new Set([UserType.STAFF, UserType.RESIDENT]));
|
65 | 26 | // const authorizedByStaff = () =>
|
66 | 27 | // isAuthorizedByUserType(new Set([UserType.STAFF]));
|
67 | 28 |
|
68 |
| -const graphQLMiddlewares = { |
69 |
| - Query: { |
70 |
| - // getNotificationsByUserId: authorizedByAllUserTypes(), |
71 |
| - // getNotificationById: authorizedByAllUserTypes(), |
72 |
| - // getStaffByIds: authorizedByStaff(), |
73 |
| - // getAllStaff: authorizedByStaff(), |
74 |
| - // getResidentsByIds: authorizedByStaff(), |
75 |
| - // getAllResidents: authorizedByStaff(), |
76 |
| - // getActiveResidents: authorizedByStaff(), |
77 |
| - // getTaskById: authorizedByAllUserTypes(), |
78 |
| - // getTasksByType: authorizedByAllUserTypes(), |
79 |
| - // getTasksByAssigneeId: authorizedByAllUserTypes(), |
80 |
| - // getTasksByAssignerId: authorizedByStaff(), |
81 |
| - // getTasksByStartDate: authorizedByAllUserTypes(), |
82 |
| - // getTasksByEndDate: authorizedByAllUserTypes(), |
83 |
| - // getTasksByStatus: authorizedByAllUserTypes(), |
84 |
| - }, |
85 |
| - Mutation: { |
86 |
| - // login: isAuthorizedByEmail("email"), |
87 |
| - // refresh: isAuthorizedByEmail("email"), |
88 |
| - // logout: isAuthorizedByUserId("userId"), |
89 |
| - // resetPassword: isAuthorizedByEmail("email"), |
90 |
| - // sendNotification: authorizedByAllUserTypes(), |
91 |
| - // deleteUserNotification: authorizedByStaff(), |
92 |
| - // updateSeenNotification: authorizedByAllUserTypes(), |
93 |
| - // sendAnnouncement: authorizedByStaff(), |
94 |
| - // addStaff: authorizedByStaff(), |
95 |
| - // updateStaff: authorizedByStaff(), |
96 |
| - // deleteStaff: authorizedByStaff(), |
97 |
| - // addResident: authorizedByStaff(), |
98 |
| - // updateResident: authorizedByStaff(), |
99 |
| - // deleteResident: authorizedByStaff(), |
100 |
| - // redeemCredits: authorizedByStaff(), |
101 |
| - // createTask: authorizedByAllUserTypes(), |
102 |
| - // updateTask: authorizedByAllUserTypes(), |
103 |
| - // deleteTask: authorizedByAllUserTypes(), |
104 |
| - // assignTask: authorizedByStaff(), |
105 |
| - // changeTaskStatus: authorizedByStaff(), |
106 |
| - // addWarning: authorizedByStaff(), |
107 |
| - // deleteWarning: authorizedByStaff(), |
108 |
| - }, |
109 |
| -}; |
| 29 | +// const graphQLMiddlewares = { |
| 30 | +// Query: { |
| 31 | +// // getNotificationsByUserId: authorizedByAllUserTypes(), |
| 32 | +// // getNotificationById: authorizedByAllUserTypes(), |
| 33 | +// // getStaffByIds: authorizedByStaff(), |
| 34 | +// // getAllStaff: authorizedByStaff(), |
| 35 | +// // getResidentsByIds: authorizedByStaff(), |
| 36 | +// // getAllResidents: authorizedByStaff(), |
| 37 | +// // getActiveResidents: authorizedByStaff(), |
| 38 | +// // getTaskById: authorizedByAllUserTypes(), |
| 39 | +// // getTasksByType: authorizedByAllUserTypes(), |
| 40 | +// // getTasksByAssigneeId: authorizedByAllUserTypes(), |
| 41 | +// // getTasksByAssignerId: authorizedByStaff(), |
| 42 | +// // getTasksByStartDate: authorizedByAllUserTypes(), |
| 43 | +// // getTasksByEndDate: authorizedByAllUserTypes(), |
| 44 | +// // getTasksByStatus: authorizedByAllUserTypes(), |
| 45 | +// }, |
| 46 | +// Mutation: { |
| 47 | +// // sendNotification: authorizedByAllUserTypes(), |
| 48 | +// // deleteUserNotification: authorizedByStaff(), |
| 49 | +// // updateSeenNotification: authorizedByAllUserTypes(), |
| 50 | +// // sendAnnouncement: authorizedByStaff(), |
| 51 | +// // addStaff: authorizedByStaff(), |
| 52 | +// // updateStaff: authorizedByStaff(), |
| 53 | +// // deleteStaff: authorizedByStaff(), |
| 54 | +// // addResident: authorizedByStaff(), |
| 55 | +// // updateResident: authorizedByStaff(), |
| 56 | +// // deleteResident: authorizedByStaff(), |
| 57 | +// // redeemCredits: authorizedByStaff(), |
| 58 | +// // createTask: authorizedByAllUserTypes(), |
| 59 | +// // updateTask: authorizedByAllUserTypes(), |
| 60 | +// // deleteTask: authorizedByAllUserTypes(), |
| 61 | +// // assignTask: authorizedByStaff(), |
| 62 | +// // changeTaskStatus: authorizedByStaff(), |
| 63 | +// }, |
| 64 | +// }; |
110 | 65 |
|
111 |
| -export default applyMiddleware(executableSchema, graphQLMiddlewares); |
| 66 | +// export default applyMiddleware(executableSchema, graphQLMiddlewares); |
0 commit comments