GraphQL API
Typed GraphQL schema design with FastAPI + Strawberry
// illustrative mock, real screenshots coming soon
A GraphQL API built with FastAPI and Strawberry, showcasing schema design, typed resolvers, and a clean, well-structured API surface.
$ cat problem.md
REST endpoints sprawl as clients' data needs grow; a typed GraphQL schema gives clients exactly what they ask for with a single, self-documenting contract.
$ whoami --role
Design & build (solo)
- Python
- FastAPI
- Strawberry
- GraphQL
$ cat approach.md
- 01Schema-first design with Strawberry's Python type system
- 02Typed resolvers wired into FastAPI
- 03Self-documenting, introspectable API surface
$ ls highlights/
$ cat api.md
A schema-first GraphQL API: typed Strawberry types, resolver composition into a single Query/Mutation root, and DataLoader batching to kill N+1 queries. Everything below is taken straight from the published source.
// Argument names shown from the resolver source; the live GraphQL Playground at /graphql is the canonical schema.
Types
UserType
A user, and the author of a post.
- id: Int!
- name: String!
- email: String!
PostType
A post with its nested author.
- id: Int!
- title: String!
- content: String!
- author: UserType!
Queries
users
List all users.
- users: [UserType!]!
posts
List all posts with authors.
- posts: [PostType!]!
post
Fetch a single post by id (raises if missing).
- post(post_id: Int!): PostType!
Mutations
createUser
Create a user; rejects a duplicate email.
- createUser(name: String!, email: String!): UserType!
createPost
Create a post for an existing author.
- createPost(title: String!, content: String!, author_id: Int!): PostType!
updatePost
Patch a post's title and/or content.
- updatePost(post_id: Int!, title: String, content: String): PostType!
deletePost
Delete a post by id.
- deletePost(post_id: Int!): Boolean!
Examples
query GetAllPosts {
posts {
id
title
content
author {
id
name
}
}
}{
"data": {
"posts": [
{
"id": 1,
"title": "GraphQL Rocks",
"content": "Really loving this",
"author": { "id": 1, "name": "Jane Doe" }
}
]
}
}mutation {
createPost(title: "GraphQL Rocks", content: "Really loving this", authorId: 1) {
id
title
author { name }
}
}