fix missing type annotations for graphql query field arguments

This commit is contained in:
2026-05-19 02:03:35 +08:00
parent b58f74d59b
commit 419af38684
4 changed files with 24 additions and 15 deletions
+5 -2
View File
@@ -1,18 +1,21 @@
import strawberry
from typing import Optional
from strawberry.types import Info
from app.graphql.types import UserType
from app.models import User
from app.graphql.context import CustomContext
@strawberry.type
class Query:
@strawberry.field
async def me(self, info) -> Optional[UserType]:
async def me(self, info: Info[CustomContext, None]) -> Optional[UserType]:
# 从 context 获取当前登录用户
user = await info.context.get_current_user()
# Strawberry 会自动将 SQLAlchemy 实例映射为 UserType
return user
@strawberry.field
def get_user_by_handle(self, info, handle: str) -> Optional[UserType]:
def get_user_by_handle(self, info: Info[CustomContext, None], handle: str) -> Optional[UserType]:
db = info.context.db
return db.query(User).filter(User.handle == handle).first()