graphql-python / graphql-python/graphene-django
DRF ChoiceField does not work with Graphene-Django
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 760
- PR merge metrics
- No merged PRs in 30d
Description
When using `SerializerMutation` with Graphene-Django 3.0.0b7, DRF's `ChoiceField` doesn't seem to work correctly:
1. Two identical enum types (but with different names) are created in the GraphQL schema
2. Using any of the choices in the mutation input results in an error like`"\"foo.BAR\" is not a valid choice."`
[Minimal demo project](https://github.com/jmp/graphene-django-enum-example)
Reproduction steps:
1. Clone the demo project:
```sh
git clone git@github.com:jmp/graphene-django-enum-example.git
```
2. Set up the project:
```sh
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```
3. Generate the GraphQL schema:
```sh
python manage.py graphql_schema --out schema.graphql
```
4. Open `schema.graphql` and you can see an enum `AppDummyFooChoices` defined as
```graphql
enum AppDummyFooChoices {
"""First"""
FIRST
"""Second"""
SECOND
"""Third"""
THIRD
}
```
In the schema, you can also see a duplicate enum defined as
```graphql
enum foo {
"""First"""
FIRST
"""Second"""
SECOND
"""Third"""
THIRD
}
```
5. Run the project, navigate to http://127.0.0.1:8000/graphql and run the following query:
```graphql
mutation {
dummyMutation(input: {
foo: FIRST
}) {
id
errors {
field
messages
}
}
}
```
You will get an error:
```json
{
"data": {
"dummyMutation": {
"id": null,
"errors": [
{
"field": "foo",
"messages": [
"\"foo.FIRST\" is not a valid choice."
]
}
]
}
}
}
```
**Expected behavior:**
1. In the GraphQL schema, there should be only one enum type `AppDummyFooChoices`.
2. There should be no error when trying to use the enum value `FIRST` in the mutation
**Related issues:**
* #517
**Environment:**
- Version: 3.0.0b7
- Platform: macOS
Contributor guide
Assessment
This issue has not been assessed yet.