graphene-django-extras icon indicating copy to clipboard operation
graphene-django-extras copied to clipboard

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

Open Cimmanuel opened this issue 4 years ago • 9 comments

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?

Cimmanuel avatar Jun 29 '20 22:06 Cimmanuel

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

ZuluPro avatar Jun 30 '20 02:06 ZuluPro

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.

jstacoder avatar Jun 30 '20 06:06 jstacoder

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

Cimmanuel avatar Jun 30 '20 07:06 Cimmanuel

Perso I use a Filterset for filtering:

class Query(object):
    provider_app = DjangoFilterPaginateListField(
        AppointmentType,
        filterset_class=filtersets.AppointmentFilterSet,
        pagination=LimitOffsetGraphqlPagination(default_limit=100)
     )
```

ZuluPro avatar Jun 30 '20 10:06 ZuluPro

@ZuluPro this still gives the same issue

Cimmanuel avatar Jun 30 '20 11:06 Cimmanuel

And what is your filterset ?

ZuluPro avatar Jun 30 '20 12:06 ZuluPro

class AppType(DjangoObjectType):
    class Meta:
        model = Appointment
        filter_fields = {
            'id': ('exact',),
            'date': ('exact',),
            'status': ('exact',)
        }

Cimmanuel avatar Jun 30 '20 12:06 Cimmanuel

@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.

Cimmanuel avatar Jun 30 '20 13:06 Cimmanuel

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

danlls avatar Nov 25 '20 06:11 danlls