Imported from salunkhesandip/graphql-sample (
AGENTS.md). Install upstream withnpx skills add salunkhesandip/graphql-sample. Copyright stays with the author.
AGENTS
Scope
Instructions for AI coding agents working in this repository.
Stack
| Component | Detail |
|---|---|
| Language | Python 3.12+ |
| GraphQL | Strawberry GraphQL ≥ 0.245 |
| Framework | FastAPI ≥ 0.115 |
| Validation | Pydantic v2 |
| Server | Uvicorn (ASGI) |
| Package mgr | uv |
| Tests | pytest + httpx |
Fast Start
uv sync --extra dev # install all deps
uv run uvicorn app.main:app --reload # start dev server (http://127.0.0.1:8000)
uv run pytest # run tests
Layer Map
app/
├── main.py — FastAPI instance with GraphQL endpoint
├── store.py — In-memory state (Dict[int, Employee] + counter)
└── schema.py — Strawberry GraphQL schema (Query, Mutation, Subscription)
tests/
└── test_employees.py
Key Conventions
GraphQL Schema
- All types defined with Strawberry
@strawberry.typedecorator - Input types use
@strawberry.input - Queries, mutations, and subscriptions are separate classes
- Use Python type hints for automatic GraphQL type generation
Types
Employee: GraphQL object type with all fieldsEmployeeInput: Input type for mutations (all fields optional for updates)- Use
strawberry.IDfor ID fields - Use
Optional[...]for nullable fields
Resolvers
- Query resolvers: read-only operations
- Mutation resolvers: create, update, delete operations
- Subscriptions: real-time updates using async generators
- Raise
Exceptionfor not-found errors (mapped to GraphQL errors)
Store
- In-memory
Dict[int, Employee]with auto-incrementing ID counter reset()method for test isolation- All mutations publish events to subscription queue
Tests
- Use
httpx.AsyncClientwith FastAPI test client - GraphQL queries sent as POST to
/graphqlwith JSON body @pytest.fixture(autouse=True)withstore.reset()before/after- Classes by operation:
TestQueries,TestMutations - Assert
response.status_code == 200andresponse.json()structure
GraphQL Patterns
Query Structure
@strawberry.type
class Query:
@strawberry.field
def employee(self, id: strawberry.ID) -> Optional[Employee]:
# implementation
Mutation Structure
@strawberry.type
class Mutation:
@strawberry.mutation
def create_employee(self, name: str, email: str) -> Employee:
# implementation
Subscription Structure
@strawberry.type
class Subscription:
@strawberry.subscription
async def employee_updated(self) -> AsyncGenerator[Employee, None]:
# async generator implementation
Skill System
No dedicated skill file yet — infer GraphQL patterns from existing code.
References
- README.md — full feature walkthrough
- pyproject.toml — dependency versions
- Strawberry GraphQL Docs