In my graphql
API for Revenue field use Currency enum
from constant.
from graphene import Enum
CurrencyEnum = Enum('Currency', CURRENCY_CHOICES)
class RevenueMetrics:
revenue = graphene.Float(description='Revenue', currency=CurrencyEnum(required=True))
But now CURRENCY_CHOICES
constant has moved to DB (Currency table). There are good reasons for this (not related to graphql).
I can't figure out how to create CurrencyEnum class with dynamic filling from QuerySet of Currency table. Have an up-to-date set of Currencies.(I suppose that there is another question in the restructuring of the scheme).
graphene==2.1.8
graphene-django==2.13.0
I tried like this:
def dcm():
return Enum('Currency', tuple((c, c) for c in Currency.objects.values_list('code', flat=True)))
revenue = graphene.Float(description='Revenue', currency=dcm()(required=True))
But it still requires a schema regeneration.