Skip to content

DRF ChoiceField does not work with Graphene-Django #1280

Open
@jmp

Description

@jmp

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

Reproduction steps:

  1. Clone the demo project:
    git clone [email protected]:jmp/graphene-django-enum-example.git
  2. Set up the project:
    python3 -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
  3. Generate the GraphQL schema:
    python manage.py graphql_schema --out schema.graphql
  4. Open schema.graphql and you can see an enum AppDummyFooChoices defined as
    enum AppDummyFooChoices {
      """First"""
      FIRST
    
      """Second"""
      SECOND
    
      """Third"""
      THIRD
    }
    In the schema, you can also see a duplicate enum defined as
    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:
    mutation {
      dummyMutation(input: {
        foo: FIRST
      }) {
        id
        errors {
          field
          messages
        }
      }
    }
    You will get an error:
    {
      "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:

Environment:

  • Version: 3.0.0b7
  • Platform: macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions