graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.3k stars 769 forks source link

IntegerChoices does not output correct Enum #990

Open licx opened 4 years ago

licx commented 4 years ago

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

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

```graphql
enum ExampleType {
  A_0
  A_1
}

YES and NO are not displayed in the enum

YES and NO are displayed in the enum

enum ExampleType {
  YES
  NO
}
zbyte64 commented 4 years ago

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 commented 4 years ago

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.

stale[bot] commented 4 years ago

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.

Jan-Heussner commented 7 months ago

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