Skip to main content
Create app.py:
import asyncio

from fastql import Field, Query, Type, build_schema, execute


@Type
class User:
    id: str
    name: str


@Query
class QueryRoot:
    @Field
    def greeting(self) -> str:
        return "Hello from FastQL"

    @Field
    def user(self, id: str) -> User:
        return User(id=id, name="Ada")


schema = build_schema(query=QueryRoot)


async def main():
    result = await execute(
        schema,
        '{ greeting user(id: "1") { id name } }',
    )
    print(result.formatted())


asyncio.run(main())
Run it:
python app.py
The result contains GraphQL-shaped data:
{
  "data": {
    "greeting": "Hello from FastQL",
    "user": {"id": "1", "name": "Ada"}
  }
}
@Type turns the annotated class into a GraphQL object type. @Query applies the same field discovery contract while marking the class as an operation root. @Field makes the method a resolver-backed field; its parameter becomes a GraphQL argument and its return annotation becomes the output type. The repository continuously executes this example from docs/snippets/quickstart.py.

Run the playground

Serve the schema and explore it in a browser.