graphql-python / graphql-python/graphene
Default value for custom input object type
- 主要语言
- Python
- 星标
- 8.2k
- 派生
- 818
- PR 合并指标
- 30 天内没有已合并 PR
描述
I have a custom input object type
```
class Filters(graphene.InputObjectType):
name = graphene.String()
type = graphene.List(graphene.String)
```
and the query definition
```
class Query(graphene.ObjectType):
search = graphene.Field(
SearchResult, query=graphene.String(required=True),
filters=graphene.Argument(Filters, default_value=None)
)
```
I want to be able to provide an empty default value for the `filters` argument. With the above definition, the argument is not set as optional and I'm getting this error message:
```
{
"errors": [
{
"message": "resolve_search() missing 1 required positional argument: 'filters'",
"locations": [
{
"line": 15,
"column": 3
}
],
"path": [
"search"
]
}
],
"data": {
"search": null
}
}
```
What is the correct way to provide an empty default value for the argument of custom object type? I'm at these package versions:
`graphene==2.1.3`
`graphql-core==2.1`
`graphql-server-core==1.1.1`
贡献指南
这个仓库没有索引到贡献指南
调研方向
从报告中显示的 Filters 输入类型、Query.search 参数定义和 resolve_search 入口点开始。跟踪省略的 filters 参数及其 default_value 是如何处理的,然后使用列出的包版本验证预期的 resolver 行为。当省略的自定义输入参数能够到达 resolve_search,且不会出现报告中的缺少参数错误时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100