2021-10-03 20:00:28 +02:00
|
|
|
import strawberry
|
2019-02-20 21:58:26 +04:00
|
|
|
from fastapi import FastAPI
|
2021-10-03 20:00:28 +02:00
|
|
|
from strawberry.asgi import GraphQL
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
graphql_app = GraphQL(schema)
|
2019-02-20 21:58:26 +04:00
|
|
|
|
|
|
|
|
app = FastAPI()
|
2021-10-03 20:00:28 +02:00
|
|
|
app.add_route("/graphql", graphql_app)
|
|
|
|
|
app.add_websocket_route("/graphql", graphql_app)
|