今天想多講一些名詞解釋相關,還有python的範例喔~
@strawberry.type
class Query:
users: User = strawberry.field(resolver=get_users, description="用戶資訊")
drinks: typing.List[Drink] = strawberry.field(resolver=get_drinks, description="飲料資訊")
@strawberry.type
class Mutation:
@strawberry.mutation
def add_user(self, UserID: str, IsLogin: bool) -> Optional[User]:
try:
store_users(UserID=UserID, IsLogin=IsLogin)
return User(UserID=UserID, IsLogin=IsLogin, Created_at=datetime.now())
except :
raise Exception("Can't insert new user")
## model.py
from pydantic import BaseModel, Field
class ProductBase(BaseModel):
owner_id: str = Field(title='保管人')
owner_dept: str = Field(title='保管部門')
asset_id: str = Field(title='資產編號')
all_fields=True
import strawberry
from .models import ProductBase
## 繼承指定參數
@strawberry.experimental.pydantic.type(model=ProductBase)
class ProductType:
owner_id: strawberry.auto
owner_dept: strawberry.auto
## 繼承所有參數
@strawberry.experimental.pydantic.type(model=ProductBase, all_fields=True)
class ProductType:
pass
資料參考