Graphene Enums not working when using without creating a new class

From the documentation, it's evident that we are not bound to create new classes for using Enums.

I have the following code snippet:

from graphene import Enum, InputObjectType

    ('step', 'Step graph'),
    ('bar', 'Bar graph'),
    ('line', 'Line graph'),
    ('dot', 'Dot graph'),

class DataType(Enum):
    VELOCITY = 'velocity'
    ACCELERATION = 'accelration'

class SomeInput(InputObjectType):
    data_type = DataType('DataTypeEnum')
    graph_type = Enum('GraphTypeEnum', GRAPH_TYPES)

When I head over to GraphiQL, I am able to see SomeInput but graph_type is missing inside.

Package versions:

  • graphene-django==2.12.1
  • graphene==2.1.8

For anyone who stumbles upon this, it turns out to be something related to the initialization of the declared Enum.

The inline declaration Enum('GraphTypeEnum', GRAPH_TYPES) has to be updated like this:

Enum('GraphTypeEnum', GRAPH_TYPES)().

Back to Top