strawberry-django-plus
strawberry-django-plus copied to clipboard
Got an unexpected keyword argument 'filters'
Argument filters shows up in GraphiQL, but still got an error. It works fine before upgrading to v3.
@gql.django.type(models.Device, filters=DeviceFilter, order=DeviceOrder)
class Device(relay.Node):
name: auto
device_type: auto
location: auto
created_at: auto
edited_at: auto
is_online: auto
online_at: auto
offline_at: auto
token: auto
# FIXME: Device.autowatering_data() got an unexpected keyword argument 'filters'
@gql.django.connection(
gql.django.ListConnectionWithTotalCount[AutowateringData],
filters=AutowateringDataFilter,
order=AutowateringDataOrder,
)
def autowatering_data(self, info) -> Iterable[models.AutowateringData]:
return models.AutowateringData.objects.all()
Hey @he0119 ,
I don't think we are considering this corner case yet... I might try to take a look at that in the future.
In the mean time you can do the following:
from strawberry_django.ordering import apply as apply_order
from strawberry_django.filters import apply as apply_filters
class Device(relay.Node):
...
@gql.django.connection(
gql.django.ListConnectionWithTotalCount[AutowateringData],
)
def autowatering_data(
self,
info,
filters: AutowateringDataFilter | None = UNSET,
order: AutowateringDataOrder | None = UNSET,
) -> Iterable[models.AutowateringData]:
qs = models.AutowateringData.objects.all()
if filters is not UNSET:
qs = apply_filters(qs, info=info)
if order is not UNSET:
qs = apply_ordering(qs)
return qs
Thanks, it works now.