@@ -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
323391Turn your SQLModel entities into AI-ready tools with a single function call.
0 commit comments