One model to rule them all
Link to the Article
- Automatic GraphQL API generation
- Automatic DB Schema generation
- Automatic event generation on mutations
- Database up/down migrations
- Service auto-reload on source code change
- Support for many other database targets - MongoDB, MySQL, SQLlite..etc
- GraphQL - A fantastic middleware tech
- TypeGraphQL - A code to graphql schema generator
- MikroORM - Probably the best ORM for Typescript (support identity maps and automatic transactions)
- Typescript - A somehow decent typed language
- Mocha - An old testing framework (I tried vitest but it doesn't support reflect-metadata)
- Ulid - A robust, distributed, timebased GUID
- Apollo Server - An good looking GrapQL server - yet a resource hog
- graphql-fields-to-relations - a graphql/database relationship optimizer (now bundled in the repo)
The application requires nodejs
and docker
installed on your computer.
- Install dependencies via
pnpm i
ornpm i
- Started the dockerized Postgres database via
docker-compose up -d
- Load fixtures
pnpm loadFixtures
, this will create the supporting schema in the database - Start the graphQL server via
pnpm start
(for prod) orpnpm dev
(for dev) - Open a browser to localhost:4000/graphql
Unit tests and code coverage are fully implemented
pnpm test
pnpm coverage
MikroORM supports database migrations allow to incrementaly change the schema as features are implemented.
After developing a feature, run the following commands to create an incremental migration:
pnpm mikro-orm schema:drop --run
pnpm mikro-orm migration:up
pnpm mikro-orm migration:create
Olivier Refalo