graphql-python / graphql-python/graphene-django

enumValues not populated for Django CharFields with choices

Open
#1,069 0 comments 0 reactions 0 assignees View on GitHub
🐛bug
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

**Note: for support questions, please use stackoverflow**. This repository's issues are reserved for feature requests and bug reports.

* **What is the current behavior?**

Querying the field types of a node that has an enum field, returns that field without enumValues.

* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** via
a github repo, https://repl.it or similar (you can use this template as a starting point: https://repl.it/@jkimbo/Graphene-Django-Example).

[https://repl.it/@moritz89/Graphene-Django-Example#recipes/schema.py](https://repl.it/@moritz89/Graphene-Django-Example#recipes/schema.py)

P.S. The template seems to have a broken import of `DjangoFilterConnectionField`

* **What is the expected behavior?**

When querying the types with

```
{
__type(name: "RecipeIngredientType") {
name,
fields {
name,
__typename,
type {
name,
description,
enumValues {
name,
description
}
},
}
}
}
```

The enumValues field for the unit field should be populated with the enum values
```

{
"data": {
"__type": {
"name": "RecipeIngredientType",
"fields": [
...
{
"name": "unit",
"__typename": "__Field",
"type": {
"name": null,
"description": null,
"enumValues": null
}
}
]
}
}
}
```

* **What is the motivation / use case for changing the behavior?**

The use case is to populate a UI of a frontend with the possible choices.

* **Please tell us about your environment:**

The version as in the Poetry.lock of the above repl. This behavior can also be reproduced with Django 3.1 and 2.2 with graphene-django at 2.13.0.

* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

There exist workarounds, for example `unit = graphene.Field(graphene.Enum.from_enum(RecipeIngredient.Unit))` where the choices are defined in a Django models.TextChoices enum class.

Contributor guide

Open the contributing guide

Research direction

Start with the linked Graphene-Django example and reproduce the introspection query for RecipeIngredientType, focusing on a Django CharField with choices. Trace how Django model fields become GraphQL types and verify that the unit field exposes its choices through enumValues; the issue is done when the query returns those values without the manual graphene.Enum workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, graphql, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.