0

I get the message

Variable '$aufmassVom' got invalid value ''; Date cannot represent value: ''

when I send this graphql mutation with an empty value for "aufmassVom":

mutation {
  createParzelle(standort: "test", aufmassVom: "", besonderheiten: "test"){
    id
    standort
    aufmassVom
    besonderheiten
  }
}

My schema.py looks like that:

import graphene
from graphene_django import DjangoObjectType
from parzelle.models import Parzelle
from graphql import GraphQLError
from graphql.validation import ValidationRule


class ParzelleType(DjangoObjectType):
    class Meta:
        model = Parzelle        

    
class CreateParzelle(graphene.Mutation):
    id = graphene.Int()
    standort = graphene.String()
    aufmassVom = graphene.Date(required=False)
    besonderheiten = graphene.String()
        
    class Arguments:
        standort = graphene.String()
        aufmassVom = graphene.Date(required=False)
        besonderheiten = graphene.String()
            
    def mutate(self, info, standort, aufmassVom, besonderheiten):
        
        if not aufmassVom:
            return GraphQLError('Required field date is missing')
                    
        parzelle = Parzelle(standort=standort, aufmassVom=aufmassVom, besonderheiten=besonderheiten)
        parzelle.save()

        return CreateParzelle(
            id=parzelle.id,
            standort=parzelle.standort,
            aufmassVom=parzelle.aufmassVom,
            besonderheiten=parzelle.besonderheiten                
        )

I would expect that I get the message "Required field date is missing" as defined in my schema.py if the value for "aufmassVom" is null (empty) and not the message "Variable '$aufmassVom' got invalid value ''; Date cannot represent value: ''".

If I change the type of "aufmassVom" from date to string everything works as expected.

What I'm doing wrong?

Andre
  • 623
  • 2
  • 9
  • 20

0 Answers0