graphene-django-extras
graphene-django-extras copied to clipboard
How to stop DjangoFilterPaginateListField from returning all instances of a model class
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?
Can you give an the model and/or a query example ?
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.
What do you mean "return the result"? Kindly demonstrate with a snippet
Perso I use a Filterset
for filtering:
class Query(object):
provider_app = DjangoFilterPaginateListField(
AppointmentType,
filterset_class=filtersets.AppointmentFilterSet,
pagination=LimitOffsetGraphqlPagination(default_limit=100)
)
```
@ZuluPro this still gives the same issue
And what is your filterset ?
class AppType(DjangoObjectType):
class Meta:
model = Appointment
filter_fields = {
'id': ('exact',),
'date': ('exact',),
'status': ('exact',)
}
@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.
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