mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-23 22:29:34 -05:00
Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
26 lines
424 B
Python
26 lines
424 B
Python
import strawberry
|
|
from fastapi import FastAPI
|
|
from strawberry.fastapi import GraphQLRouter
|
|
|
|
|
|
@strawberry.type
|
|
class User:
|
|
name: str
|
|
age: int
|
|
|
|
|
|
@strawberry.type
|
|
class Query:
|
|
@strawberry.field
|
|
def user(self) -> User:
|
|
return User(name="Patrick", age=100)
|
|
|
|
|
|
schema = strawberry.Schema(query=Query)
|
|
|
|
|
|
graphql_app = GraphQLRouter(schema)
|
|
|
|
app = FastAPI()
|
|
app.include_router(graphql_app, prefix="/graphql")
|