djangographqlstrawberry-graphql

Strawberry GraphQL Django limiting filtering options in GraphiQL interface


So I have two graphql filters for a foreign key that works in Strawberry GraphQL Django v0.31.

@strawberry.django.filters.filter(models.Client, lookups=True)
class ClientFilter:
    id:auto
    name:auto

@strawberry.django.filters.filter(models.Matter, lookups=True)
class MatterFilter:
    id: auto
    client:'ClientFilter'
    category:auto

In the GraphiQL page they produce a filter that looks like this:

enter image description here

I don't need all the filter fields for the user because some of them don't make sense like using isNull or a regex field for an id. Is there a way to limit the filter options so it is less cluttered?


Solution

  • A bit late to the party, but yes you can do that but you would have to define your own input like so:

    @strawberry.input
    class LimitedFilterLookup(Generic[T]):
        i_contains: Optional[T] = UNSET
    
    

    And then instead of using auto for the fields of the filter you would declare them like this:

    @strawberry.django.filters.filter(models.Client)
    class ClientFilter:
        name: LimitedFilterLookup[str]