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

IntegerChoices does not output correct Enum

Open licx opened this issue 5 years ago • 4 comments

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)

licx avatar Jun 14 '20 12:06 licx

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.

zbyte64 avatar Jun 15 '20 17:06 zbyte64

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.

zbyte64 avatar Jun 16 '20 21:06 zbyte64

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.

stale[bot] avatar Aug 27 '20 00:08 stale[bot]

Are there any Updates or maybe someone has found a workaround?

janheussner avatar Mar 19 '24 16:03 janheussner