strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

How to validate input model field?

Open web5gogogo opened this issue 1 year ago • 1 comments

@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?

web5gogogo avatar Sep 03 '22 02:09 web5gogogo

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.

ThirVondukr avatar Sep 05 '22 11:09 ThirVondukr

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.

humphrey avatar Sep 26 '22 00:09 humphrey