Skip to content

PureLeach/GraphQL-Books-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 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:
git clone [https://github.com/PureLeach/backend-test-maslov.ai.git](https://github.com/PureLeach/GraphQL-Books-API.git)
cd GraphQL-Books-API
  1. Create and activate a virtual environment:
poetry shell

NOTE: If it doesn't work, install plugin poetry self add poetry-plugin-shell

  1. Install dependencies:
poetry install
  1. Create'.env` or specify the environment variables:
cp .env.example .env
  1. Run PostgreSQL and apply migrations
docker-compose up -d
make migrate
  1. Start the app:
make run
  1. Open GraphQL Playground:

Go to the browser: http://localhost:8000/graphql


🔍 Examples of requests

1. Get all the books

query {
  books {
    title
    author {
      name
    }
  }
}

2. Get books by author (e.g., Oscar Wilde - ID = 1)

query {
  books(authorIds: [1]) {
    title
    author {
      name
    }
  }
}

3. Search for books by part of title (case is not important)

query {
  books(search: "adventures") {
    title
    author {
      name
    }
  }
}

4. Get no more than 2 books

query {
  books(limit: 2) {
    title
    author {
      name
    }
  }
}

5. Combination of all filters

query {
  books(authorIds: [3], search: "Adventures", limit: 1) {
    title
    author {
      name
    }
  }
}

6. No match (empty result)

query {
  books(search: "Nonexistent") {
    title
    author {
      name
    }
  }
}

🌐 Interfaces

About

A simple application on FastAPI + Strawberry GraphQL to retrieve a list of books and authors from PostgreSQL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors