Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Got an unexpected keyword argument 'filters' #245

Open
he0119 opened this issue Jun 17, 2023 · 2 comments
Open

Got an unexpected keyword argument 'filters' #245

he0119 opened this issue Jun 17, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@he0119
Copy link

he0119 commented Jun 17, 2023

Argument filters shows up in GraphiQL, but still got an error. It works fine before upgrading to v3.

image
image

Related code:
he0119/smart-home@9922c78#diff-af3602ede1befa32df28d961add5b48aaf07992465fb6d0f1dbb50e4a0568cdbR79-R85

@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()
@bellini666
Copy link
Member

bellini666 commented Jun 17, 2023

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

@bellini666 bellini666 added enhancement New feature or request help wanted Extra attention is needed labels Jun 17, 2023
@he0119
Copy link
Author

he0119 commented Jun 18, 2023

Thanks, it works now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants