A simple application on FastAPI + Strawberry GraphQL to retrieve a list of books and authors from PostgreSQL.
- Python 3.12+
- FastAPI
- Strawberry (GraphQL)
- PostgreSQL
- Databases
- asyncpg
- yoyo (migrations)
- ruff
- mypy
- docker-compose
- Clone the repository:
git clone [https://github.com/PureLeach/backend-test-maslov.ai.git](https://github.com/PureLeach/GraphQL-Books-API.git)
cd GraphQL-Books-API- Create and activate a virtual environment:
poetry shellNOTE: If it doesn't work, install plugin poetry self add poetry-plugin-shell
- Install dependencies:
poetry install- Create'.env` or specify the environment variables:
cp .env.example .env- Run PostgreSQL and apply migrations
docker-compose up -d
make migrate- Start the app:
make run- Open GraphQL Playground:
Go to the browser: http://localhost:8000/graphql
query {
books {
title
author {
name
}
}
}query {
books(authorIds: [1]) {
title
author {
name
}
}
}query {
books(search: "adventures") {
title
author {
name
}
}
}query {
books(limit: 2) {
title
author {
name
}
}
}query {
books(authorIds: [3], search: "Adventures", limit: 1) {
title
author {
name
}
}
}query {
books(search: "Nonexistent") {
title
author {
name
}
}
}- Swagger UI: http://localhost:8000/docs
- Strawberry GraphiQL playground: http://localhost:8000/graphql
- pgAdmin: http://localhost:5050