Overview - Pydantic-resolve

2 min read Original article ↗

Open Source · Pydantic v2 · Python 3.10+

Declarative Data Assembly

A BFF toolkit for Python. Compose complex nested APIs declaratively — zero N+1, zero boilerplate.

pip install pydantic-resolve

# Sprint has 10 tasks, each needs owner
for task in sprint.tasks:
    task.owner = await get_user(task.owner_id)
 # 10 queries!
class TaskView(BaseModel):
    owner_id: int
    owner: Optional[UserView] = None

    def resolve_owner(self, loader=Loader(user_loader)):
        return loader.load(self.owner_id)
 # 1 query!

Batch Loading

Auto-batch queries via DataLoader pattern. 100 lookups become 1 query.

Post Processing

Compute derived fields after all nested data is resolved. Counts, aggregates, formatting.

Cross-Layer Data Flow

ExposeAs, SendTo, Collector — pass context down or aggregate data up without traversal code.

ER Diagram + AutoLoad

Centralize relationship declarations. Reuse across models, GraphQL, and MCP services.

GraphQL Generation

Auto-generate GraphQL schema and resolvers from your ER Diagram.

MCP Service

Expose GraphQL APIs to AI agents via Model Context Protocol.

1 resolve_*

2 Nested Tree

3 post_*

4 Cross-Layer

5 ERD + AutoLoad

6 GraphQL / MCP

Entity + Use Case

ER Diagram defines entities and their relationships — it naturally serves as both the domain model and the use-case boundary.

DB Agnostic

Loaders abstract away the data source. Swap SQLAlchemy for Django or Tortoise ORM — your models stay untouched.

Multi-Presentation

One ERD drives REST API responses, GraphQL queries, and MCP services — without duplication.

Ready to eliminate N+1 queries?

Start with a single resolve method. Scale to ER Diagram when you're ready.