A modern blog API built with Flask and GraphQL using Strawberry.
- GraphQL API with Strawberry
- JWT Authentication
- Blog post management
- User management
- GraphQL Playground
- Docker support
git clone <repository-url>
cd flask-graphql-blog-api
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements-dev.txtCopy .example.env and update with your settings:
cp .example.env .env
# Edit .env with your configurationpython setup_db.pyThis creates the database and adds sample data:
- Admin user:
admin/admin123 - Author user:
johndoe/password123 - Sample blog posts
python app.pyVisit http://localhost:5000/api/graphql for the GraphQL Playground.
First, login to get an access token:
mutation {
login(loginInput: { username: "admin", password: "admin123" }) {
accessToken
user {
id
username
fullName
}
}
}query {
posts {
id
title
excerpt
isPublished
author {
username
fullName
}
}
}Include the JWT token in the Authorization header: Bearer <your-token>
mutation {
createPost(
postInput: {
title: "My New PostModel"
content: "This is the content of my post..."
isPublished: true
}
) {
id
title
slug
author {
username
}
}
}query {
searchPosts(searchTerm: "GraphQL") {
id
title
excerpt
}
}src/
├── app/
│ ├── __init__.py # App factory
│ ├── config.py # Configuration
│ ├── extensions.py # Flask extensions
│ ├── models/ # SQLAlchemy models
│ ├── schemas/ # GraphQL types & schema
│ ├── services/ # Business logic
│ └── api/ # GraphQL endpoints
├── app.py # Application entry point
└── setup_db.py # Database initialization
# Format code
ruff format .
# Lint code
ruff check . --fix
# Pre-commit hooks
pre-commit run --all-filescd dockerfiles
docker-compose -f docker-compose.dev.yml up --buildhello- Simple test queryposts(publishedOnly, limit)- Get all postspost(id)- Get post by IDpostBySlug(slug)- Get post by slugpostsByAuthor(authorId)- Get posts by authorsearchPosts(searchTerm)- Search postsusers- Get all usersuser(id)- Get user by IDme- Get current user (requires auth)
register(userInput)- Register new userlogin(loginInput)- Login usercreatePost(postInput)- Create post (requires auth)updatePost(id, postInput)- Update post (requires auth)deletePost(id)- Delete post (requires auth)publishPost(id)- Publish post (requires auth)
This is a portfolio project demonstrating modern Python API development practices.

