Skip to content

How to exclude some fields in nested (related models) fields? #1267

@sandnima

Description

@sandnima

For instance:

# types
...

class CategoryType(DjangoObjectType):
    class Meta:
        model = Brand
        fields = ("name", "detail")

class BookType(DjangoObjectType):
    class Meta:
        model = Book
        fields = ("title", "category", "other_fields")

# queries
...

class CategoriesQuery(graphene.ObjectType):
    categories = graphene.List(CategoryType)
    
    @staticmethod
    def resolve_category_list(root, info):
        return Category.objects.all()

class BooksQuery(graphene.ObjectType):
    books= graphene.List(BookType)
    
    @staticmethod
    def resolve_book_list(root, info):
        return Book.objects.all()

How can I exclude detail field querying book list,
without excluding in CategoryType itself (which may be used in other queries like category list)?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions