Graphene-django: Mutation update how pass null value

Created on 14 Dec 2017  路  5Comments  路  Source: graphql-python/graphene-django

model
date = models.DateField(blank=True, null=True)
schema
date = graphene.types.datetime.Date()

mutation ($var1: Date){ updateModel( id: 1, date: $var1 ) { model { id date } } }

{"var1": null}

{ "errors": [ { "message": "mutate() missing 1 required positional argument: 'date'", "locations": [ { "line": 2, "column": 3 } ] } ], "data": { "updateModel": null } }

question

Most helpful comment

@juliocebrito

I haven't tried this myself recently on the latest graphene/graphene-django versions. But based on these docs for graphene, I believe you should be able to do the following:


class UpdateModel(graphene.Mutation):
    class Arguments:
        id = graphene.ID()
        date = graphene.Date(required=False)

    @staticmethod
    def mutate(root, info, id, date=None):
        # handle empty date

Let me know if that answers your question and works for you.

All 5 comments

@juliocebrito

I haven't tried this myself recently on the latest graphene/graphene-django versions. But based on these docs for graphene, I believe you should be able to do the following:


class UpdateModel(graphene.Mutation):
    class Arguments:
        id = graphene.ID()
        date = graphene.Date(required=False)

    @staticmethod
    def mutate(root, info, id, date=None):
        # handle empty date

Let me know if that answers your question and works for you.

Sadly this does not work for me using 2.0.1. :|

I keep getting None when passing null in my client. (vs undefined)

@Eraldo can you share a relevant code snippet?

Closing this down due to inactivity.

@juliocebrito

I haven't tried this myself recently on the latest graphene/graphene-django versions. But based on these docs for graphene, I believe you should be able to do the following:

class UpdateModel(graphene.Mutation):
    class Arguments:
        id = graphene.ID()
        date = graphene.Date(required=False)

    @staticmethod
    def mutate(root, info, id, date=None):
        # handle empty date

Let me know if that answers your question and works for you.

This worked for me
Thanks!

Was this page helpful?
0 / 5 - 0 ratings