Coder Social home page Coder Social logo

Comments (3)

basilfx avatar basilfx commented on May 19, 2024 1

@eamigo86 Thanks for fixing. I will continue to evaluate this and submit ideas/bugs/comments to further improve this great package!

from graphene-django-extras.

basilfx avatar basilfx commented on May 19, 2024

An attempt: I have changed the following (not sure if it works according to your ideas):

In fields.py around line 227:

def list_resolver(self, manager, filterset_class, filtering_args, root, info, **kwargs):
    qs = queryset_factory(manager, info.field_asts, filtering_args, **kwargs)
    filter_kwargs = {k: v for k, v in kwargs.items() if k in filtering_args}

    qs = manager.get_queryset()
    qs = filterset_class(data=filter_kwargs, queryset=qs).qs
    count = qs.count()

    return DjangoListObjectBase(
        count=count,
        results=qs,
        results_field_name=self.type._meta.results_field_name
    )

In utils.py around line 113:

def queryset_factory(manager, fields_asts=None, filtering_args=None, **kwargs):

    if filtering_args is None:
        filtering_args = {}
    select_related = []
    prefetch_related = []
    filter_kwargs = {k: v for k, v in kwargs.items() if k in filtering_args}
    available_related_fields = get_related_fields(manager.model)

    for f in kwargs.keys():
        temp = available_related_fields.get(f.split('_', 1)[0], None)
        if temp:
            if (temp.many_to_many or temp.one_to_many) and temp.name not in prefetch_related:
                prefetch_related.append(temp.name)
            else:
                select_related.append(temp.name)

    if fields_asts:
        select_related, prefetch_related = recursive_params(fields_asts[0].selection_set, available_related_fields, select_related, prefetch_related)

    if select_related and prefetch_related:
        return manager.select_related(*select_related).prefetch_related(*prefetch_related)
    elif not select_related and prefetch_related:
        return manager.prefetch_related(*prefetch_related)
    elif select_related and not prefetch_related:
        return manager.select_related(*select_related)
    return manager

I basically removed all filter(**kwargs) calls from the queryset_factory and moved them back to the list_resolver method.

from graphene-django-extras.

eamigo86 avatar eamigo86 commented on May 19, 2024

Hello again @basilfx. First of all I would like to thank you very much for your comments and for your help. This bug, like the other two, are fixed in the more recent version 0.0.1b10.

image

from graphene-django-extras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.