Reusing the types from the DjangoObjectType in the graphene

21 Views Asked by At

I have created the PreferencesNode from the DjangoObjectType which contains the gateway provider as TextChoices.

class GatewayProvider(models.TextChoices):
    STRIPE = "stripe", "Stripe"
    RAZORPAY = "razorpay", "Razorpay"
class PreferencesNode(DjangoObjectType):
    class Meta:
        model = Preferences
        exclude_fields = ("user_id",)

Now I want to use AccountPreferencesGatewayProviderChoices enum (created via PreferencesNode). How can I do this?

Currently I am creating another enum inheriting graphene.Enum.

class GatewayProviderEnum(graphene.Enum):
    STRIPE = GatewayProvider.STRIPE.value
    RAZORPAY = GatewayProvider.RAZORPAY.value

But this is creating redundant enum type.

output from the graphiql

Here I am asking the question. How can I use the AccountPreferencesGatewayProviderChoices enumeration which is created through DjangoObjectType, in the different mutation or query as argument without redefining the type?

0

There are 0 best solutions below