44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
import strawberry
|
|
from typing import List, Optional
|
|
from datetime import datetime
|
|
from app.utils.format import get_image_url
|
|
|
|
@strawberry.type
|
|
class UserType:
|
|
id: strawberry.ID
|
|
email: str
|
|
name: Optional[str]
|
|
handle: Optional[str]
|
|
avatar: Optional[str]
|
|
following_count: int
|
|
follower_count: int
|
|
created_at: datetime
|
|
|
|
# 动态解析字段:例如自动处理头像的绝对路径
|
|
@strawberry.field
|
|
def avatar_url(self) -> Optional[str]:
|
|
return get_image_url(self.avatar) if self.avatar else None
|
|
|
|
@strawberry.type
|
|
class WorkspaceType:
|
|
id: strawberry.ID
|
|
name: str
|
|
slug: str
|
|
logo: Optional[str]
|
|
description: Optional[str]
|
|
storage_used: int
|
|
|
|
# 支持前端按需加载关联的成员
|
|
@strawberry.field
|
|
def members(self, info) -> List["WorkspaceMemberType"]:
|
|
from app.models import WorkspaceMember
|
|
db = info.context.db
|
|
return db.query(WorkspaceMember).filter(WorkspaceMember.workspace_id == self.id).all()
|
|
|
|
@strawberry.type
|
|
class WorkspaceMemberType:
|
|
id: strawberry.ID
|
|
workspace_id: str
|
|
user_id: Optional[str]
|
|
role: str
|
|
status: str |