Skip to content

Unable to make required/mandatory "custom" filter field #763

@jerinpetergeorge

Description

@jerinpetergeorge

How can we make a "custom filter method/field" as a required/mandatory field?

Describe the Bug

Consider that I have this filter class

@strawberry_django.filter(PayoutExecution, lookups=True)
class AnyFilter:
    status: BaseFilterLookup[PayoutExecutionStatus]  # Mandatory

    @strawberry_django.filter_field()
    def custom_field(
        self,
        info: Info,
        value: BaseFilterLookup[PayoutExecutionStatus],
        prefix: str,
        queryset: QuerySet,
    ):
        return Q(field_1=True)

For this AnyFilter type, the generated schema looks like this

# schema.graphql
input AnyFilter {
  status: PayoutExecutionStatusBaseFilterLookup!
  AND: AnyFilter
  OR: AnyFilter
  NOT: AnyFilter
  DISTINCT: Boolean
  customField: PayoutExecutionStatusBaseFilterLookup
}

As we can see, the customField is not required/mandatory - how can we fix that?

System Information

  • Operating system: Linux
  • Python version: Python 3.11.5
  • Strawberry version (if applicable): strawberry-graphql-django==0.52.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions