← Back to all products
$10
GraphQL Boilerplate
Lightweight GraphQL server built on Python's standard library, zero dependencies.
JSONMarkdownPython
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 9 files
graphql-boilerplate/
├── LICENSE
├── README.md
├── examples/
│ └── queries.example.json
├── free-sample.zip
├── guide/
│ ├── 01_graphql-boilerplate.md
│ ├── 02_features.md
│ └── 03_quick-start.md
├── index.html
└── src/
└── main.py
📖 Documentation Preview README excerpt
GraphQL Boilerplate
Lightweight GraphQL server built on Python's standard library. Zero dependencies.
Part of the API Launchpad toolkit by [CodeVault](https://codevault.dev).
Features
- Schema definition with Python dataclasses — no SDL files needed
- Field resolvers with argument passing and context support
- Query parsing for queries, mutations, and nested field selections
- Introspection support —
__schemaand__typequeries for tooling compatibility - Built-in GraphQL Explorer — HTML-based query editor served at
/ - CORS enabled — ready for frontend integration out of the box
- Zero dependencies — runs on Python stdlib only
Quick Start
# Start the server
python3 src/main.py
# Open the GraphQL Explorer in your browser
open http://localhost:4000/
# Or use curl
curl -X POST http://localhost:4000/graphql \
-H 'Content-Type: application/json' \
-d '{"query": "{ users { id name email } }"}'
Defining Your Schema
Register a type
from main import schema, FieldDef
schema.register_type("Product", [
FieldDef(name="id", type_name="ID"),
FieldDef(name="name", type_name="String"),
FieldDef(name="price", type_name="Float"),
FieldDef(name="in_stock", type_name="Boolean"),
], description="A product in the catalog")
Register a query resolver
schema.register_query(
"products", "Product",
lambda args: list(products_db.values()),
is_list=True,
description="List all products",
)
schema.register_query(
"product", "Product",
lambda args: products_db.get(args.get("id", "")),
arguments={"id": "ID"},
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
src/main.py
#!/usr/bin/env python3
"""
GraphQL Boilerplate — Lightweight GraphQL Server
==================================================
A Python GraphQL server built entirely on the standard library. Supports
schema definition via Python dataclasses, field resolvers, query parsing,
type validation, introspection, and error formatting.
Zero dependencies. Just run: python3 main.py
Part of the API Launchpad toolkit by DataNest.
License: MIT
"""
from __future__ import annotations
import json
import logging
import re
from dataclasses import dataclass, field
from datetime import datetime, timezone
from http.server import HTTPServer, BaseHTTPRequestHandler
from typing import Any, Callable
from urllib.parse import parse_qs, urlparse
# ---------------------------------------------------------------------------
# Configuration
# ---------------------------------------------------------------------------
DEFAULT_HOST = "0.0.0.0"
DEFAULT_PORT = 4000
SERVER_TITLE = "GraphQL Boilerplate"
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
)
logger = logging.getLogger("graphql-server")
# ---------------------------------------------------------------------------
# Type System — Define your schema types as Python dataclasses
# ---------------------------------------------------------------------------
# Scalar type mapping: GraphQL type name → Python type for validation
SCALAR_TYPES: dict[str, type] = {
"String": str,
"Int": int,
"Float": float,
# ... 529 more lines ...