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

When passing null as input in mutation, value does not show up in args #103

Closed
BossGrand opened this issue Feb 1, 2017 · 10 comments
Closed

Comments

@BossGrand
Copy link
Member

BossGrand commented Feb 1, 2017

For example the following will raise an exception when number is null

 class EditNumber(graphene.ClientIDMutation):
    class Input:
        number = graphene.Int()
    
     success = graphene.Boolean()

     @classmethod
     def mutate_and_get_payload(cls, args, context, info):
           args['number'] # this raises a errror when i pass in null 

On the JS side my getVariables input is:

 getVariables() {
     return {
        number: null
     };
 }

I would expect calling args['number'] to return None instead of raising an exception if I specifically supply null as my input

Is this the desired behavior, or is this a bug?

@BossGrand BossGrand changed the title When passing null input type, value does not show up in args When passing null as input in mutation, value does not show up in args Feb 1, 2017
@imsickofmaps
Copy link

Keen to know this too

@syrusakbary
Copy link
Member

This is a bug in the GraphQL-core (and GraphQL-js version up to 0.6).
Will keep this issue open until is solved :)

@imsickofmaps
Copy link

@syrusakbary I think you are referring to graphql-python/graphene#280 ?

@syrusakbary
Copy link
Member

@imsickofmaps yes :)

@insolite
Copy link

insolite commented Feb 16, 2017

Seems like the same thing happens with variables as well. As @prokofiev mentioned here:
graphql-python/graphene#280 (comment)
null can be passed using variables and there is no Unexpected Name "null" anymore. But instead, I am getting Variable "$var1" of required type "String!" was not provided. Of course everything is ok when var1 is "test" or so.

@BossGrand
Copy link
Member Author

Solved in 2.0

@Eraldo
Copy link

Eraldo commented Apr 26, 2018

@BossGrand I don't get it. :|
When passing null in my client I get None on the server. How am I able to distinguish between null and not provided?

@jkimbo
Copy link
Member

jkimbo commented Apr 29, 2018

@Eraldo if you pass null from the client the argument will be None in the mutate function. However if you don't provide the argument then an argument won't be provided to the mutation function.

Example:

class SomeMutation(graphene.Mutation):
    class Arguments:
        name = graphene.String()

    ok = graphene.Boolean()

    def mutate(self, info, **args):
		# If no name provided then `args = {}`
		# If name is `null` then `args = { 'name': None }`

@tlinhart
Copy link

tlinhart commented Nov 10, 2018

@jkimbo So the correct way to define mutate function is to use **args instead of explicitly naming the arguments? It seems so, because if I define arguments explicitly, they are None during execution in both cases (if I set them null and if I don't provide them).

Also, it seems that the only way how I can set argument null is to use a variable, I can't set the argument null directly (see this). I find this a bit odd and couldn't find any reason for this. Also, I found this PR from what I think it should be possible or supported.

@cbouvier15
Copy link

Hi there!

I'm using graphene==2.1.8 and graphene-django==2.10.1. It is not working as expected for me..

When I send value=null from graphiql the argument is ignored, instead of appearing with null value.
Is this still a problem? Am I doing something wrong?

Thanks in advance!

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

No branches or pull requests

8 participants