graphql-python / graphql-python/graphene

Default value for custom input object type

Offen
#856 14 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
✨ enhancement good first issue
Vorherrschende Sprache
Python
Sterne
8.2k
Forks
818
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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`

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.