š² Nest.js GraphQL Example
June 11, 2022 Ā· View on GitHub
An example of how to create and test a GraphQL Server with Nest.js and TypeORM
Features
- GraphQL server with Apollo
- Code first approach to build the schema
- TypeORM to connect with MySQL
- Unit tests and E2E tests
- PNPM for a fast and efficient installation
- Check code quality with MegaLinter
- Check continuous integration with github actions
- Run the necessary services with docker compose
Run Locally
Clone the project
git clone https://github.com/leosuncin/nest-graphql-example.git
Go to the project directory
cd nest-graphql-example
Install dependencies
pnpm install
Create a .env from the example one and customize it with your environment variables
cp .env.example .env
Start the services using Docker Compose
docker-compose up -d
Run migrations to create the DB schema
pnpm typeorm migration:run
Start the server
pnpm start:dev
Environment Variables
To run this project, you will need to add the following environment variables to your .env file
MYSQL_DATABASE the name of the database to connect in the MySQL instance (required)
MYSQL_ROOT_PASSWORD The password of the root user to connect to the MySQL instance (required)
DATABASE_URL a connection string to the MySQL instance, example mysql://root@localhost/example-db (required)
You can copy the example .env and edit the values
cp .env.example .env
Running Tests
To run unit tests, run the following command:
pnpm test
To run e2e tests (the MySQL instance must be available), run the following command:
pnpm test:e2e
Tech Stack
Server: Typescript, MySQL, Nest.js, TypeORM, Apollo
Test: Jest, SuperTest
DevOps: Docker Compose
Author
š¤ Jaime Leonardo Suncin Cruz
- Twitter: @jl_suncin
- Github: @leosuncin
- LinkedIn: @jaimesuncin
Show your support
Give a āļø if this project helped you!
Related
Here are some more example projects with Nest.js
License
Release under the terms of GPL v3