https://github.com/pureleach/backend-test-maslov.ai
A simple application on FastAPI + Strawberry GraphQL to retrieve a list of books and authors from PostgreSQL
https://github.com/pureleach/backend-test-maslov.ai
fastapi graphql postgresql
Last synced: about 1 year ago
JSON representation
A simple application on FastAPI + Strawberry GraphQL to retrieve a list of books and authors from PostgreSQL
- Host: GitHub
- URL: https://github.com/pureleach/backend-test-maslov.ai
- Owner: PureLeach
- Created: 2025-05-05T20:00:17.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-06T11:59:32.000Z (about 1 year ago)
- Last Synced: 2025-05-06T12:50:26.426Z (about 1 year ago)
- Topics: fastapi, graphql, postgresql
- Language: Python
- Homepage:
- Size: 49.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 📚 GraphQL Books API
A simple application on FastAPI + Strawberry GraphQL to retrieve a list of books and authors from PostgreSQL.
## 🚀 Technologies used
- Python 3.12+
- FastAPI
- Strawberry (GraphQL)
- PostgreSQL
- Databases
- asyncpg
- yoyo (migrations)
- ruff
- mypy
- docker-compose
## 📦 Installation and startup
1. **Clone the repository:**
```bash
git clone https://github.com/PureLeach/backend-test-maslov.ai.git
cd backend-test-maslov.ai
````
2. **Create and activate a virtual environment:**
```bash
poetry shell
```
NOTE: If it doesn't work, install plugin `poetry self add poetry-plugin-shell`
3. **Install dependencies:**
```bash
poetry install
```
4. **Create'.env` or specify the environment variables:**
```bash
cp .env.example .env
```
5. **Run PostgreSQL and apply migrations**
```bash
docker-compose up -d
make migrate
```
6. **Start the app:**
```bash
make run
```
7. **Open GraphQL Playground:**
Go to the browser: [http://localhost:8000/graphql](http://localhost:8000/graphql)
---
## 🔍 Examples of requests
### 1. Get all the books
```graphql
query {
books {
title
author {
name
}
}
}
```
### 2. Get books by author (e.g., Oscar Wilde - ID = 1)
```graphql
query {
books(authorIds: [1]) {
title
author {
name
}
}
}
```
### 3. Search for books by part of title (case is not important)
```graphql
query {
books(search: "adventures") {
title
author {
name
}
}
}
```
### 4. Get no more than 2 books
```graphql
query {
books(limit: 2) {
title
author {
name
}
}
}
```
### 5. Combination of all filters
```graphql
query {
books(authorIds: [3], search: "Adventures", limit: 1) {
title
author {
name
}
}
}
```
### 6. No match (empty result)
```graphql
query {
books(search: "Nonexistent") {
title
author {
name
}
}
}
```
## 🌐 Interfaces
- Swagger UI: http://localhost:8000/docs
- Strawberry GraphiQL playground: http://localhost:8000/graphql
- pgAdmin: http://localhost:5050