docs_src/graphql_/tutorial001_py310.py
raw| 1 | import strawberry |
| 2 | from fastapi import FastAPI |
| 3 | from strawberry.fastapi import GraphQLRouter |
| 4 | |
| 5 | |
| 6 | @strawberry.type |
| 7 | class User: |
| 8 | name: str |
| 9 | age: int |
| 10 | |
| 11 | |
| 12 | @strawberry.type |
| 13 | class Query: |
| 14 | @strawberry.field |
| 15 | def user(self) -> User: |
| 16 | return User(name="Patrick", age=100) |
| 17 | |
| 18 | |
| 19 | schema = strawberry.Schema(query=Query) |
| 20 | |
| 21 | |
| 22 | graphql_app = GraphQLRouter(schema) |
| 23 | |
| 24 | app = FastAPI() |
| 25 | app.include_router(graphql_app, prefix="/graphql") |