eamigo86 / graphene-django-extras

Extras functionalities for Graphene-Django
MIT License
414 stars 102 forks source link

How to stop DjangoFilterPaginateListField from returning all instances of a model class #144

Open Cimmanuel opened 4 years ago

Cimmanuel commented 4 years ago

DjangoFilterPaginateListField simply returns manager.all() and ignores all parameters passed to the field. For instance, l have the following:

class Query(graphene.ObjectType):
    variable = DjangoFilterPaginateListField(
        SomeType,
        id=graphene.ID(required=True)
    )

    @login_required
    def resolve_variable(self, info, id):
        try:
            variable_two = Model.objects.get(pk=id)
        except Model.DoesNotExist:
            return GraphQLError('Model does not exist')
        else:
            return variable_two.foreign_field.all()

Instead of getting results related to the id supplied, I simply get Model.objects.all(). How do I solve this?

ZuluPro commented 4 years ago

Can you give an the model and/or a query example ?

jstacoder commented 4 years ago

Looks like in the try, you’re not returning the result, so it’s just moving along and returning the all call at the end. Just return the result.

Cimmanuel commented 4 years ago

What do you mean "return the result"? Kindly demonstrate with a snippet

ZuluPro commented 4 years ago

Perso I use a Filterset for filtering:

class Query(object):
    provider_app = DjangoFilterPaginateListField(
        AppointmentType,
        filterset_class=filtersets.AppointmentFilterSet,
        pagination=LimitOffsetGraphqlPagination(default_limit=100)
     )
Cimmanuel commented 4 years ago

@ZuluPro this still gives the same issue

ZuluPro commented 4 years ago

And what is your filterset ?

Cimmanuel commented 4 years ago
class AppType(DjangoObjectType):
    class Meta:
        model = Appointment
        filter_fields = {
            'id': ('exact',),
            'date': ('exact',),
            'status': ('exact',)
        }
Cimmanuel commented 4 years ago

@ZuluPro I think you are missing the point. Filtering via configured filterset works fine. The problem is with filtering via the supplied argument. Please check the resolver method again.

danlls commented 3 years ago

I'm facing the same issue, its due to custom resolver being ignored when using DjangoFilterPaginateListField as described in https://github.com/eamigo86/graphene-django-extras/issues/56