Suppose I have a model like this
class Order(models.Model):
STATES = [
(1, 'Initiate'),
(2, "Brief"),
(3, "Planning"),
(4, "Price Negotiate"),
(5, "Executing"),
(6, "Pending"),
(7, "Completed"),
(8, "Canceled"),
(9, "Failed"),
(10, "Paid"),
]
state = models.PositiveSmallIntegerField(
choices=STATES,
default=1
)
When I pair this model with its Graphene object type companion
class OrderNode(graphene_django.DjangoObjectType):
class Meta:
model = Order
interfaces = (relay.Node,)
An enum type with name OrderState!
is created.
I am concerned with
- How can I query for the enums
- How can I manage enums in React with Apollo client
For the first question, I have this query
{
customer(id: "Q3VzdG9tZXJOb2RlOjE=") {
name
orders {
edges {
node {
state
}
}
}
}
}
It gives me a weird state value like A_1
and A_2
. I was expecting it to give me some meaningful value like "Initiate". How can I get the value of the kv pair enum?
For the second question, if I want to present to user a list of possible value for this enum, how can I do so?