Liel Fridman
Liel Fridman

Reputation: 1198

Graphene-django - Mutating types with enums

So, I have the following model:

class Semester(models.Model):
    course = models.ManyToManyField(Course, through='CourseSemester')

    class SemesterType(models.TextChoices):
        A = 'A', 'Winter'
        B = 'B', 'Spring'
        SUMMER = 'SU', 'Summer'

    name = models.CharField(
        max_length=200,
        choices=SemesterType.choices,
        default=SemesterType.A,
    )
    year = models.IntegerField()

I try to add a mutation to add a new semester. Graphene-django seems to automatically generate an Enum field for me, but how can I get it inside the arguments?

According to the github issues, something like SemesterType._meta.fields['name'] should work, but I can't get it right, even with wrapping it inside graphene.Argument.

It is possible to tell Graphene not to convert it to Enum, however I'd rather avoid that if possible.

Any clue how to get that right?

Upvotes: 2

Views: 1322

Answers (1)

Krzysieqq
Krzysieqq

Reputation: 1121

You should add convert_choices_to_enum = False to your DjangoObjectType

More information is in documentation in Choices to Enum conversion section

Upvotes: 3

Related Questions