graphql-python / graphql-python/graphene-django

enumValues not populated for Django CharFields with choices

未关闭
#1,069 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
🐛bug
主要语言
Python
星标
4.4k
派生
760
PR 合并指标
30 天内没有已合并 PR

描述

**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.

贡献指南

打开贡献指南

调研方向

从链接的 Graphene-Django 示例开始,复现针对 RecipeIngredientType 的 introspection 查询,重点关注带有 choices 的 Django CharField。跟踪 Django 模型字段如何变成 GraphQL 类型,并验证 unit 字段是否通过 enumValues 暴露其 choices;当查询无需手动的 graphene.Enum workaround 即可返回这些值时,该 issue 就完成了。

由索引模型根据 Issue 内容生成。

评估

技术栈
django, graphql, python
领域
api, backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。