[BACKLOG] Move all multi-project types and schema into one single lib
Is your feature request related to a problem? Please describe.
Both cugetreg-web and cugetreg-api have separate type definitions for GraphQL types (cugetreg-api= auto-generated from .graphql files, cugetreg-web= manual declaration). This mean changes to cugetreg-api'schema can break without cugetreg-web realizing it.
cugetreg-api and cu-scraper both connects to MongoDB to access course data. The mongo schema is currently separated as well, and we need to change both of them when we make changes to the database schema.
Describe the solution you'd like
- Create a lib in monorepo as
schemato act as a single source of type declaration between multiple projects (mostly frontend and backend). For GraphQL types, utilize auto-generated types from .graphql files for both projects. Note: this will require heavy refactoring on the frontend code.
- MongoDB schemas: used by
cugetreg-apiandcu-scraper - GraphQL types: used by
cugetreg-apiandcugetreg-web
- Relocate mongo schema in
cugetreg-apito this project, to share withcu-scraper(after we migrate scraper to this repo)
Additional context
Don't worry about cu-scraper for now as it may be deprecated in favor of new implementation soon.
Task Advisor @bombnp
Summary
Motivation and Changes for Frontend
- Currently, we have two sets of GraphQL schema/types, one is in backend, one is in frontend
- We should have Single Source of Truth. Like every company will do, we will use backend graphql as main schema
- We will have codegen (
libs/codegen) that read backend's graphql schema and generate types/documents/react hooks - All apollo queries on the frontend should now all import types/documents/react hooks from
libs/codegen
Backend
- Like frontend, we declare mongoose schema and graphql schema separately. This may cause some mismatch. We need to find a solution to write schema once and it generates the other. @Nacnano
PR Spliting
In this ticket, I would like to split PR into 2 (or more part) for easier reviewing. Sub-PRs are independent and can be merged separately.
Sub-PR 1: Frontend #415
libs/codegen, generate GraphQL types and documents fromcugetreg-api's GraphQL schemas.- Convert all frontend (
cugetreg-web) queries to use generated type fromlibs/codegen - Remove
@thinc-org/chula-coursesfrom dependencies
Sub-PR 2: Backend [TODO]
- Convert to code first schema?
@Leomotors since we're not using Nx anymore, does codegen still work? The generated code is probably fine, but the action to generate it required Nx right?
@Leomotors since we're not using Nx anymore, does codegen still work? The generated code is probably fine, but the action to generate it required Nx right?
We need to convert the command into turbo way. Which is not that complex.