[Answered ]-Using Graphql with Django : Reverse Foreign key relationship using related name for all objects

1👍

Use graphene_django.DjangoListField:

from graphene_django import DjangoListField, DjangoObjectType

class CategoryType(DjangoObjectType):
    grocery = DjangoListField(GroceryType)

Alternatively, implement a resolver:

import graphene
from graphene_django import DjangoObjectType

class CategoryType(DjangoObjectType):
    grocery = graphene.List(GroceryType)

    @staticmethod
    def resolve_grocery(parent, info):
        return parent.grocery.all()
👤aaron

Leave a comment