strawberry
strawberry copied to clipboard
How to validate input model field?
@strawberry.input
class OrderParameters():
offerer: str
zone: str
order_type: int = strawberry.field(
description="The order type, support: {}".format(OrderType.dict())
)
start_time: int
end_time: int
salt: int
offer: List[OfferItem]
consideration: List[ConsiderationItem]
zone_hash: str
total_original_consideration_items: int
conduit_key: str
counter: int
I have many input fields, and each field needs to be verified separately?
Hello, what kind of validation are we talking about? If it's simple validation that doesn't have to interact with your data storage/db you can use pydantic, otherwise you should check them in your code.
Probably not the most elegant solution, but I had existing Django ModelForms, so I wrote my own helper function that generates a base strawberry input from a ModelForm. I then use that form in my mutation just like I would in a Django view function.