Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-null InputField with default_value is not supported #1220

Closed
radekwlsk opened this issue Jun 29, 2020 · 7 comments
Closed

Non-null InputField with default_value is not supported #1220

radekwlsk opened this issue Jun 29, 2020 · 7 comments
Labels

Comments

@radekwlsk
Copy link
Contributor

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

@jkimbo
Copy link
Member

jkimbo commented Jun 29, 2020

@radekwlsk is this on Graphene v2? I think this should be fixed in v3 with the upgrade to graphql-core v3.

@radekwlsk
Copy link
Contributor Author

@radekwlsk is this on Graphene v2? I think this should be fixed in v3 with the upgrade to graphql-core v3.

Yeah, that's v2. I will have to check that on v3 but not sure if our production app is ready for that jump. I will have to create some test project for it.

@radekwlsk
Copy link
Contributor Author

radekwlsk commented Jun 30, 2020

@jkimbo I've bumped the dependencies to

graphql-core = "~=3.1.1"
graphene = "==3.0b3"
graphene-django = "==3.0.0b4"

and it still errors out when required input field with a default is not provided. But from what you are saying I take that it is an issue with graphql-core rather than graphene?

@jkimbo
Copy link
Member

jkimbo commented Jun 30, 2020

Hmm thats strange, I've added a test to try and show that it should work: https://github.com/graphql-python/graphene/compare/input-type-default

Can you check your code with the test that I've written?

@radekwlsk
Copy link
Contributor Author

Same thing with your test code copied

>       assert not result.errors
E       assert not [GraphQLError('Argument "myField" has invalid value {}.\nIn field "name": Expected "String!", found null.\nIn field "goodPerson": Expected "Boolean!", found null.')]
E        +  where [GraphQLError('Argument "myField" has invalid value {}.\nIn field "name": Expected "String!", found null.\nIn field "goodPerson": Expected "Boolean!", found null.')] = <graphql.execution.base.ExecutionResult object at 0x7ff0f60c9e00>.errors

I will check dependency tree once again.

@radekwlsk
Copy link
Contributor Author

@jkimbo Ok, I've once again installed all dependencies (correctly this time) and it indeed works on v3.

Closing

@jkimbo
Copy link
Member

jkimbo commented Jun 30, 2020

Glad to hear!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants