Open bibekyess opened 2 years ago
I think we need to add support for default_factory inside strawberry.argument
Any news on this?
Factory functions aside, these tips might help:
{}
as a default: def get_data(where: JSON = {})
.def get_data(where: Optional[JSON] = {})
. Because then it is valid for the client to pass an explicit null, the resolver should handle that case for correctness, and it is not clear what the difference would be. So why not disallow the unwanted use case.null
is preferred, it can be the default: def get_data(where: Optional[JSON] = None)
.There is case for array fields where it is more logical to use empty list as default rather null(None). Maybe creation of some sort of marker could resolve the issue.
There is case for array fields where it is more logical to use empty list as default rather null(None). Maybe creation of some sort of marker could resolve the issue.
That already works too: arg: list[...] = []
.
I'd be happy to review a PR if anyone has time to implement this 😊
There is case for array fields where it is more logical to use empty list as default rather null(None). Maybe creation of some sort of marker could resolve the issue.
That already works too:
arg: list[...] = []
.
mmm.... It doesn`t work in inputs or types, I suppose you implemented strawberry decorators on top of dataclasses which also have such problem, but in their case you can use field(default_factory=list), which kinda solves the issue. So for now we forced to use optional array fields or required one without default, which is a bit annoying.
It seems strawberry doesn't support default_factory for query arguments. Like in example below:
Here, I couldn't find a way to set
where
argument be dict using default_factory. Using the same code as above result in AST error unless we replacestrawberry.field(default_factory=dict)
or{}
byNone
.Upvote & Fund