Graphene-django: IntegerChoices does not output correct Enum

Created on 14 Jun 2020  路  3Comments  路  Source: graphql-python/graphene-django

When generating a schema from a model that has as a field of type IntegerChoices https://docs.djangoproject.com/en/3.0/ref/models/fields/#choices), the choices are not displayed in the schema

  • What is the current behavior?
from django.db import models
from graphene_django.types import DjangoObjectType

# Model
class ExampleModel(models.Model):
    class Answer(models.IntegerChoices):
        NO = 0
        YES = 1

#Schema
class ExampleType(DjangoObjectType):
    class Meta:
        model = ExampleModel

When generating the schema with ./manage.py graphql_schema --schema example_app.schema.root_schema --out schema.graphql the output looks like this

enum ExampleType {
  A_0
  A_1
}

YES and NO are not displayed in the enum

  • What is the expected behavior?

YES and NO are displayed in the enum

enum ExampleType {
  YES
  NO
}
  • What is the motivation / use case for changing the behavior?

  • Please tell us about your environment:

    • Version:
      Python 3.7
      graphene-django==2.10.1
      graphene==2.1.8
      Django==3.0.6
    • Platform:
      MacOs
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

鉁╡nhancement

Most helpful comment

I think this is technically an enhancement to add support for IntegerChoices and TextChoices, and I like it allot! IMHO we have always struggled to deliver an clean Enum experience and I this could deliver that.

All 3 comments

I think this is technically an enhancement to add support for IntegerChoices and TextChoices, and I like it allot! IMHO we have always struggled to deliver an clean Enum experience and I this could deliver that.

Current challenge is that the django field gets a choice tuple and not the enum itself. Probably means we can't autoamgically link the enum when defining the ObjectType.

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amiyatulu picture amiyatulu  路  3Comments

timothyjlaurent picture timothyjlaurent  路  3Comments

Northshoot picture Northshoot  路  4Comments

dan-klasson picture dan-klasson  路  4Comments

khankuan picture khankuan  路  4Comments