graphene icon indicating copy to clipboard operation
graphene copied to clipboard

Default `default_value` should be `Undefined` instead of `None` in `Argument` and `Field`

Open steverice opened this issue 4 years ago • 2 comments

In graphql-core, the default_value for a GraphQLArgument is set to Undefined if it is not given. This corresponds to the behavior in value_from_ast, in which an argument that has not been supplied is given the default_value iff that default is not Undefined.

In other words, if the code specifies a default_value for an argument, use it if there is no value provided. If the code does not specify a default_value, do not supply a default value if none is provided.

Graphene breaks this expectation by setting the default_value to None if none is provided in Argument and in Field.

This was resolved for InputField in https://github.com/graphql-python/graphene/pull/1111, but it should also be changed for Argument and Field since a Field can be mounted as an Argument.

From that PR:

Since GraphQL 3.0 there is a distinction between None and INVALID (no value). See also graphql-python/graphql-core#66 (comment) I think there are more bugs of this kind, but since I don't know graphene well, yet, I take baby steps.

steverice avatar Jun 29 '21 19:06 steverice

Hi is there an update on this? we have the exact same problem and cant migrate to graphene 3 because of this - it is breaking all our APIs pretty much.

samopus1io avatar Mar 23 '22 18:03 samopus1io

I've just encountered this issue as it breaks our API as well. It seems it was fixed in https://github.com/graphql-python/graphene/commit/19ebf08339263f0446235ddffbbab0e6d3f11699, at least for the Argument type.

tlinhart avatar May 18 '22 09:05 tlinhart

As @tlinhart mentioned, this is fixed in the newest release.

erikwrede avatar Sep 23 '22 11:09 erikwrede