[Answered ]-How to customize graphene-django response?

1๐Ÿ‘

Iโ€™m not sure of a simple way of doing it in graphene-django/python. It seems like there are ways to achieve this in NodeJS. However if your goal is to add some data to every single response, you can make a super class that all your classes inherit from. This means your extra_field will always be there, but it will be inside data.

class MyBaseType(DjangoObjectType):
    class Meta:
        abstract = True

    extra_field = graphene.JSONField()

    def resolve_extra_field(self, info):
        return #something

And then inherit in your normal classes.

class UserType(MyBaseType):
    class Meta:
        model = User
๐Ÿ‘คrymanso

Leave a comment