Skip to content

Non-null InputField with default_value is not supported #1220

@radekwlsk

Description

@radekwlsk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions