-
Notifications
You must be signed in to change notification settings - Fork 828
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
Saving null value for nullable fields #280
Comments
Hi @prokofiev! You can actually use the So currently you can do: class Undefined(object): pass
class Query(graphene.ObjectType):
field = graphene.String(
input=graphene.String(default_value=Undefined)
) It might be interesting to set |
Hi @syrusakbary ! class Foo(models.Model):
''' Example model with nullable field '''
not_null = models.CharField(max_length=10)
nullable = models.CharField(max_length=10, null=True) Next my use cases:
How can I use "default_value" to set the nullable field to null (case 3)? |
Hey @prokofiev, after thinking about this I realized this could be approached in a easier way. As Something like @classmethod
def mutate_and_get_payload(cls, input, context, info):
not_null = 'UNDEFINED'
if 'not_null' in input:
# ....
not_null = input['not_null']
# .... Does that make sense? |
Hi @syrusakbary ! |
After checking, I realized that this query: mutation UpdateFoo{
saveFoo (input:{
clientMutationId:"1"
id:"id"
nullable: null
}) {
...
}
} Is actually not valid as For this reason I guess that some client's check when the value is null and then skip it (Relay?). As an extra exercise, I checked that arguments and input fields that are not provided don't fill the dictionary with None values: def test_does_not_include_arguments_that_were_not_set():
InputObject = GraphQLInputObjectType(
name='InputObject',
fields={
'value': GraphQLInputObjectField(GraphQLString, default_value=None),
'other': GraphQLInputObjectField(GraphQLString, default_value=None)
}
)
def resolver(data, args, *_):
print args
return 'other' in args['c']
schema = GraphQLSchema(GraphQLObjectType(
'Type',
{
'field': GraphQLField(
GraphQLInt,
resolver=resolver,
args={
'a': GraphQLArgument(GraphQLBoolean),
'b': GraphQLArgument(GraphQLBoolean),
'c': GraphQLArgument(InputObject),
'd': GraphQLArgument(GraphQLInt),
'e': GraphQLArgument(GraphQLInt),
}
)
}
))
ast = parse('{ field(c: {value: "3"}) }')
result = execute(schema, ast)
assert result.data == {
'field': False
} If you can provide more insights that I might be missing please let me know. |
null value may be passed like this:
variables:
|
Hey @prokofiev , did you find a workaround for this? I'm struggling with exactly the same problem and am very interested in your approach. The least hack I could come up with, is to always require all arguments and then use 'input.get('myVar', None)' to retrieve them in 'mutate_and_get_payload()'. Even setting the field to be required and having a default value will not make it appear in the input dict... |
If somebody knows how to fix it more correctly, please let me know. |
@prokofiev Hehe, thanks for the snippet. Will look into it. |
@syrusakbary have you seen this pull request? graphql now supports nullable types. Can we get some support for this in graphene? |
Any progress on this? |
@NiekHoekstra Does a PR exist yet for this? If not are you willing to take the patch and turn it into a PR? :) |
We are having the same problem! |
This issue is solved in graphene 2.0 and should be closed |
Does someone have an example for 2.0? |
@BossGrand I am still having this problem with null values. my server receives this as **args (at mutate function): However, if the client sends this:
My python **args param receives only 2 keys/values:
(where I would expect receiving My packages versions:
Should this issue be reopened ? Thanks in advance |
@rdemetrescu i get the same thing... so not sure if this is really fixed. |
@arif-hanif, just noticed that mutations using relay work perfectly. |
I have seen this query:
fail with:
However when I pass title as a "variable" it does work. |
graphql-core is responsible for the query parsing so that is where adding @rdemetrescu I can't reproduce your issue. If you are still having problems can you open a new issue with everything needed to reproduce it? Closing this for now |
@jkimbo Hi, this is still unsolved and the link to the graphql-core pull request is dead. Can you please advise where this is/was tracked? Thanks! |
@brabeji we will shortly be releasing graphene v3 that is based on graphql-core v3 which is a complete rewrite and has support for null values. You can try out the beta release now. Release notes are here: https://github.com/graphql-python/graphene/wiki/v3-release-notes |
@jkimbo Hello ! |
Need this change as well. It does not make sense to remove null values in the parameters. |
need this as well |
Is there any breaking change in V3 ? Maybe we can use the latest beta while waiting the official release ? Edit:
instead of :
|
Had same issue, we need to wait for django-graphql-jwt update |
I had a problem saving the null values in the mutations. Is it possible to implement functionality to
get_argument_values
function could distinguish passed null value and not passed value?I think it can be implemented similar to the
executor.ececute_fields
using Undefined.The text was updated successfully, but these errors were encountered: