What I am trying to do
I am trying to return Enum values with their names so if I run query:
{
getFruits {
fruits
}
}
I want the output:
{
data: {
fruits: [
{APPLE: 1},
{ORANGE: 2},
{MANGO: 3}
]
}
}
But I get an error:
{
"errors": [
{
"message": "unhashable type: 'EnumMeta'",
"locations": [
{
"line": 20,
"column": 3
}
],
"path": [
"getFruits"
]
}
],
"data": {
"getFruits": null
}
}
I did look at the docs but it doesn't help.
What is the purpose of returning Enum ?
To display valid choices that can be used as arguments for subsequent queries.
My Code:
Type:
class EnumType(graphene.Enum):
APPLE = 1
ORANGE = 2
MANGO = 3
class FruitType(graphene.ObjectType):
fruits = graphene.List(EnumType)
Resolver:
class MyQuery(graphene.ObjectType):
get_fruits = graphene.Field(FruitType)
def resolve_get_fruits(self, info):
fruits = [
{EnumType.APPLE: 1},
{EnumType.ORANGE: 2},
{EnumType.MANGO: 3}
]
return FruitType(
fruits=fruits
)
I don't know if that is the right way to do it since I am new to GraphQL in general.