Skip to content

Commit b33109f

Browse files
sohumshah2RayahhhmedShzmjjordansbenjamin
authored
Update getCourseInfo and getCoursesList queries to use graphql (#907)
* added apollo client + some helper funcs * added some helper funcs * attempt at converting timetable.ts to use graphql to handle term details * updated getCoursesList with gql for initial review * improvement: integrated gql for getCoursesList * updated getCourseInfo to use graphql query (#906) * feat: make graphql query to get course info * format graphql output to match rest api output * use graphql data instead of rest api data * removed unnecessary fields from qraphql query * clean up code * clean up code * clean up code * clean up code * clean up code * removed references to old timetable scraper * removed unused logic from timetable.ts + removed 'lastUpdated' status from footer --------- Co-authored-by: ray <[email protected]> Co-authored-by: Shaam <[email protected]> Co-authored-by: jordansbenjamin <[email protected]>
1 parent 19eb91a commit b33109f

19 files changed

+428
-123
lines changed

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"style": "prettier --write 'src/**/*.{ts,tsx}' && eslint --fix 'src/**/*.{ts,tsx}'"
1717
},
1818
"dependencies": {
19+
"@apollo/client": "3.11.8",
1920
"@date-io/date-fns": "3.0.0",
2021
"@emotion/react": "11.13.0",
2122
"@emotion/styled": "11.13.0",

client/pnpm-lock.yaml

Lines changed: 161 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/App.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ const App: React.FC = () => {
115115
setTermsData,
116116
setTermNumber,
117117
setCoursesList,
118-
setLastUpdated,
119118
selectedTimetable,
120119
displayTimetables,
121120
setDisplayTimetables,
@@ -204,9 +203,8 @@ const App: React.FC = () => {
204203
* Retrieves the list of all courses from the scraper backend
205204
*/
206205
const fetchCoursesList = async () => {
207-
const { courses, lastUpdated } = await getCoursesList(year, term);
206+
const { courses } = await getCoursesList(term);
208207
setCoursesList(courses);
209-
setLastUpdated(lastUpdated);
210208
};
211209

212210
if (year !== invalidYearFormat) fetchReliably(fetchCoursesList);
@@ -294,7 +292,7 @@ const App: React.FC = () => {
294292
const codes: string[] = Array.isArray(data) ? data : [data];
295293
Promise.all(
296294
codes.map((code) =>
297-
getCourseInfo(year, term, code, isConvertToLocalTimezone).catch((err) => {
295+
getCourseInfo(term, code, isConvertToLocalTimezone).catch((err) => {
298296
return err;
299297
}),
300298
),

client/src/api/config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ApolloClient, InMemoryCache } from '@apollo/client';
2+
13
export enum Env {
24
DEV = 'development',
35
TEST = 'test',
@@ -10,14 +12,16 @@ interface Config {
1012
auto: string;
1113
server: string;
1214
}
13-
15+
const HASURAGRES_GRAPHQL_API = 'https://graphql.csesoc.app/v1/graphql';
1416
const LOCAL = 'http://localhost:3001';
15-
const LIVE = 'https://timetable.devsoc.app';
17+
18+
export const client = new ApolloClient({
19+
uri: HASURAGRES_GRAPHQL_API,
20+
cache: new InMemoryCache(),
21+
});
1622

1723
const API_CONFIG: Record<string, Config> = Object.freeze({
1824
[Env.DEV]: { timetable: `${LOCAL}/api`, auto: `${LOCAL}/api/auto`, server: `${LOCAL}/api` },
1925
[Env.TEST]: { timetable: `${LOCAL}/api`, auto: `${LOCAL}/api/auto`, server: `${LOCAL}/api` },
20-
[Env.MOCK]: { timetable: `${LIVE}/api`, auto: `${LOCAL}/api/auto`, server: `${LOCAL}/api` },
21-
[Env.PROD]: { timetable: `${LIVE}/api`, auto: `/api/auto`, server: `/api` },
2226
});
2327
export const API_URL: Config = API_CONFIG[import.meta.env.VITE_APP_ENVIRONMENT || Env.DEV];

0 commit comments

Comments
 (0)