Default value for custom input object type
See original GitHub issueI 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
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Setting the Default Value of Input Fields - Salesforce Help
Select the field. · Click Configure in the Properties pane. · Select the source of the default value. Option, Description. Fixed Value, Use...
Read more >How to setup Custom field (insight object type) default value?
Solved: Is it possible to setup default value for Custom field which is Insight obejct type? This Custom field type doesn't have "Edit...
Read more >How to set a default value for a field in graphene
1. For default values... · name : string. Override the name of the Field. · description : string. A description of the type...
Read more >Input Object Types - Hot Chocolate - ChilliCream
Input object type definitions differ from object types only in the used keyword and in that their fields can not have arguments.
Read more >Default value - Async-graphql Book
You can define default values for input value types. Below are some examples. Object field.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For now, I’ve ended up with the following solution:
Since now, it’s possible to do:
It produces the correct schema and passes the default value I was expecting instead of the empty dict.
Yeah using
Filters()
should work, so I guess there’s a bug somewhere 😃I’ll see if I can have a look at it soon