Skip to content

How would one implement totalCount or count on DjangoFilterConnectionField? #636

Closed
@changeling

Description

@changeling

With Connection, one can implement a count on edges like so:

from graphene import Connection, ConnectionField, Node, Int
from graphene_django import DjangoObjectType
from ..models import Place

class Thing_Type(DjangoObjectType):
    class Meta:
        model = Thing
        interfaces = (Node, )


class Thing_Connection(Connection):
    class Meta:
        node = Thing_Type
    count = Int()

    def resolve_count(root, info):
        return len(root.edges)


class Query(object):
    things = ConnectionField(Thing_Connection)

    def resolve_things(root, info, **kwargs):
        return Thing.objects.all()
   return len(root.edges)

Given that DjangoFilterConnectionField won't accept a Connection, but requires a DjangoObjectType, how would one implement an equivalent count?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions