Skip to content

No ability to get QuerySet in relay.Connection when use custom resolver in graphene.ObjectType #249

@raprek

Description

@raprek

When I want to add some custom resolver (some complicated filter for example) for graphene.ObjectType I will lose opportunity to get filtered count number in Connection and etc. Example:

class Connection(relay.Connection):
    """Connection class"""

    class Meta:
        """Meta class"""
        abstract = True

    total_count = graphene.Int()

    def resolve_total_count(root, info, **kwargs):
        """Counts total number of documents with filters"""
        return root.iterable.count() 

class SomeModel(MongoengineObjectType):
    class Meta:
        connection_class = Connection

    
class SomeQueryRely(graphene.ObjectType):
    q = MongoengineConnectionField(SomeModel, filter_one = graphene.String(name="filter_one"), filter_two =graphene.String(name="filter_two"))
    def resolve_q(self, info: GraphQLResolveInfo, **kwargs):
        query: QuerySet = info.context.queryset
        QuerySet.filter(Q(filter_one=kwargs["filter_one"]) | Q(filter_two=kwargs["filter_two"]))
        return query

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