graphene-django
graphene-django copied to clipboard
DRF ChoiceField does not work with Graphene-Django
When using SerializerMutation
with Graphene-Django 3.0.0b7, DRF's ChoiceField
doesn't seem to work correctly:
- Two identical enum types (but with different names) are created in the GraphQL schema
- Using any of the choices in the mutation input results in an error like
"\"foo.BAR\" is not a valid choice."
Reproduction steps:
- Clone the demo project:
git clone [email protected]:jmp/graphene-django-enum-example.git
- Set up the project:
python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt
- Generate the GraphQL schema:
python manage.py graphql_schema --out schema.graphql
- Open
schema.graphql
and you can see an enumAppDummyFooChoices
defined as
In the schema, you can also see a duplicate enum defined asenum AppDummyFooChoices { """First""" FIRST """Second""" SECOND """Third""" THIRD }
enum foo { """First""" FIRST """Second""" SECOND """Third""" THIRD }
- Run the project, navigate to http://127.0.0.1:8000/graphql and run the following query:
You will get an error:mutation { dummyMutation(input: { foo: FIRST }) { id errors { field messages } } }
{ "data": { "dummyMutation": { "id": null, "errors": [ { "field": "foo", "messages": [ "\"foo.FIRST\" is not a valid choice." ] } ] } } }
Expected behavior:
- In the GraphQL schema, there should be only one enum type
AppDummyFooChoices
. - 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
any progress for this issue?!
Facing the same issue on v3.1.3
Workaround is to add convert_choices_to_enum = False
to the meta class of both the ObjectType
and Mutation
classes for that model type.