strawberry
strawberry copied to clipboard
Support for non-scalar default values is broken
thanks to @cache-missing for the report!
This:
import strawberry
@strawberry.input
class InputData:
name: str = "10"
@strawberry.type
class Query:
@strawberry.field
def example(self, data: InputData = InputData()) -> str:
return data.name
schema = strawberry.Schema(query=Query)
Results in an error when not passing anything to data:
argument of type 'InputData' is not iterable
GraphQL supports non scalar types as input (they also show up in the schema), while in python you'd usually use None/UNSET as default. We should support this use case, by either adding direct support for default values or by providing a default factory.
Here's an example on the playground
Upvote & Fund
- We're using Polar.sh so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.
It can be done with an empty dict/object. The received value will still be the default input type.
def example(self, data: InputData = {}) -> str:
It can be done with an empty dict/object. The received value will still be the default input type.
def example(self, data: InputData = {}) -> str:
Thank you so much! I was running into this problem when testing and this solution worked wonders. I have no idea how the default value of {} converts to the input type but it does 👍