graphene-django-extras icon indicating copy to clipboard operation
graphene-django-extras copied to clipboard

filter_fields on Enum/ChoiceFields

Open Alir3z4 opened this issue 6 years ago • 4 comments

The request is similar to https://github.com/graphql-python/graphene-django/issues/176.

I have a DjangoSerializerType that I'm trying to set filter_fields on its choice/enum field, however the enum field happens to be simply an String type.

class Movie(models.Model):
    title = models.CharField()
    genre = models.CharField(choices=(('a', 'A'), ('b', 'B'), ('c', 'C'),))


class MovieSerializer(serializers.ModelSerializer):
    class Meta:
        model = Movie
        fields = '__all__'


class MovieType(DjangoSerializerType):

    class Meta:
        serializer_class = MovieSerializer
        filter_fields = {
            'title': ('exact', 'icontains', 'istartswith', ),
            'genre': ('exact', )  # Genre should be Enum type, but it comes as String
        }

Worth noting the genre is successfully displayed as Enum type when getting the data, but when doing query filtering it's always String.

When Filtering:

query {
    movies(genre: "a") {  # it's a string and not a type. 
    ...
    }
}

When retrieving:

query {
    movies { 
    ...
    }
}

# Result

{
   data: {
       {"title": "Batman!", genre: "A"}  # comes with value of Enum
   }
}

Any idea how this can be resolved ?

Alir3z4 avatar Oct 25 '18 20:10 Alir3z4

me too

bianchiidentity avatar Apr 18 '19 13:04 bianchiidentity

Hey guys! Is there any news on this?

I am trying out graphql (here: with graphene-django) and I also have this problem -- more specific: the filtering seems not to be working with Enums/Choices..

Thanks!

freddyli avatar Apr 27 '20 15:04 freddyli

i am facing the same issue as well

hyusetiawan avatar Jul 18 '20 09:07 hyusetiawan

I am also facing the same issue

JyothiVutukuri avatar Dec 02 '22 13:12 JyothiVutukuri