According to GraphQL spec change introduced in this pull request graphql/graphql-spec#418 it should be possible to define input field as non-null with default and make it take that default value if not provided.
- What is the current behavior?
class MyInput(graphene.InputObjectType):
name = graphene.String(required=True)
myInput = graphene.InputField(
graphene.Boolean,
default_value=True,
required=True,
)
input MyInput {
name: String!
myValue: Boolean! = true
}
when provided as {"name": "foo"} results in
{'errors': [{'message': 'Variable "$input" got invalid value {"name": "foo"}.\nIn field "myValue": Expected "Boolean!", found null.'}]}
- What is the expected behavior?
When input field has a default (true here) and is non-null providing {"name": "foo"} should results in passing {"name": "foo", "myValue": true} to the mutation and no errors.
Error
{'errors': [{'message': 'Variable "$input" got invalid value {"name": "foo"}.\nIn field "myValue": Expected "Boolean!", found null.'}]}
should only occur when input has myValue explicitly provided as null/None.
- What is the motivation / use case for changing the behavior?
That should be the default behaviour according to GraphQL spec: graphql/graphql-spec#418
According to GraphQL spec change introduced in this pull request graphql/graphql-spec#418 it should be possible to define input field as non-null with default and make it take that default value if not provided.
when provided as
{"name": "foo"}results inWhen input field has a default (
truehere) and is non-null providing{"name": "foo"}should results in passing{"name": "foo", "myValue": true}to the mutation and no errors.Error
should only occur when input has
myValueexplicitly provided asnull/None.That should be the default behaviour according to GraphQL spec: graphql/graphql-spec#418