Skip to content

Commit f0d43c8

Browse files
committed
feat: update changelog and README for AutoQueryConfig; bump version to 0.13.0
1 parent 1d8b099 commit f0d43c8

4 files changed

Lines changed: 78 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.13.0
4+
5+
- Add `AutoQueryConfig` for auto-generating `by_id` and `by_filter` queries for SQLModel entities
6+
- `by_id`: find a single entity by primary key
7+
- `by_filter`: filter entities by field values with auto-generated `FilterInput` type
8+
- Pass `auto_query_config` to `GraphQLHandler` to enable; handler discovers all entity subclasses automatically
9+
- Update README.md with Auto-Generated Standard Queries documentation
10+
311
## 0.12.0
412
- migrate from mcp to fastmcp
513

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,74 @@ result = await handler.execute("""
318318
# }
319319
```
320320

321+
## Auto-Generated Standard Queries
322+
323+
Pass `AutoQueryConfig` to `GraphQLHandler` to automatically generate `by_id` and `by_filter` queries for every entity — no `@query` decorator needed.
324+
325+
### Configuration
326+
327+
```python
328+
from sqlmodel_graphql import GraphQLHandler, AutoQueryConfig
329+
330+
config = AutoQueryConfig(
331+
session_factory=async_session, # Required: async session factory
332+
default_limit=10, # Default limit for by_filter
333+
generate_by_id=True, # Generate by_id query
334+
generate_by_filter=True, # Generate by_filter query
335+
)
336+
337+
handler = GraphQLHandler(base=BaseEntity, auto_query_config=config)
338+
```
339+
340+
When `auto_query_config` is provided, the handler discovers **all** entity subclasses (not only those with decorators) and attaches standard queries.
341+
342+
### Generated Queries
343+
344+
For an entity named `User` with primary key `id`:
345+
346+
| Method | GraphQL Field | Return Type | Description |
347+
|--------|--------------|-------------|-------------|
348+
| `by_id` | `userById(id: Int!): User` | `User \| None` | Find a single entity by primary key |
349+
| `by_filter` | `userByFilter(filter: UserFilterInput, limit: Int): [User!]!` | `list[User]` | Filter entities by field values |
350+
351+
**FilterInput** is auto-generated per entity. All fields are optional — only non-`None` values are used as `WHERE` conditions (exact match).
352+
353+
### Example
354+
355+
```graphql
356+
# Get by ID
357+
{
358+
userById(id: 1) {
359+
id
360+
name
361+
email
362+
posts { title }
363+
}
364+
}
365+
366+
# Filter by fields
367+
{
368+
userByFilter(filter: { name: "Alice" }, limit: 5) {
369+
id
370+
name
371+
email
372+
}
373+
}
374+
375+
# List all (no filter)
376+
{
377+
userByFilter(limit: 20) {
378+
id
379+
name
380+
}
381+
}
382+
```
383+
384+
**Notes:**
385+
- `by_id` requires exactly one primary key field (detected from `id` field or `primary_key=True`).
386+
- `by_filter` supports exact match only; for complex queries, write custom `@query` methods.
387+
- Existing methods on the entity are not overridden.
388+
321389
## MCP Integration
322390

323391
Turn your SQLModel entities into AI-ready tools with a single function call.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "sqlmodel-graphql"
3-
version = "0.12.0"
3+
version = "0.13.0"
44
description = "GraphQL SDL generation and query optimization for SQLModel"
55
authors = [{ name = "tangkikodo", email = "allmonday@126.com" }]
66
readme = "README.md"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)