2021-10-03 20:00:28 +02:00
|
|
|
import strawberry
|
2019-02-20 21:58:26 +04:00
|
|
|
from fastapi import FastAPI
|
2025-01-06 12:24:17 +01:00
|
|
|
from strawberry.fastapi import GraphQLRouter
|
2019-02-20 21:58:26 +04:00
|
|
|
|
|
|
|
|
|
2021-10-03 20:00:28 +02:00
|
|
|
@strawberry.type
|
|
|
|
|
class User:
|
|
|
|
|
name: str
|
|
|
|
|
age: int
|
2019-02-20 21:58:26 +04:00
|
|
|
|
|
|
|
|
|
2021-10-03 20:00:28 +02:00
|
|
|
@strawberry.type
|
|
|
|
|
class Query:
|
|
|
|
|
@strawberry.field
|
|
|
|
|
def user(self) -> User:
|
|
|
|
|
return User(name="Patrick", age=100)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
schema = strawberry.Schema(query=Query)
|
|
|
|
|
|
|
|
|
|
|
2025-01-06 12:24:17 +01:00
|
|
|
graphql_app = GraphQLRouter(schema)
|
2019-02-20 21:58:26 +04:00
|
|
|
|
|
|
|
|
app = FastAPI()
|
2025-01-06 12:24:17 +01:00
|
|
|
app.include_router(graphql_app, prefix="/graphql")
|