strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
421 stars 122 forks source link

FilterLookup filters has strange behavior when chaining them together. #595

Closed pfcodes closed 4 months ago

pfcodes commented 4 months ago

Describe the Bug

I'm trying to implement filters so theres always one fixed filter which is always set and then additional filters chained on top of it to drill down a set of results. So for example, say I want to filter for a person that has a profession of "driver" and in addition to driver they are also both a mechanic and engineer. I would expect this to work:

filters: {
  professions: {
    id: { exact: "driver" },
    AND: {
      id: { inList: ["mechanic", "engineer"] },
    },
  },
}

But it doesn't work at all... I tried doing this:

filters: {
  professions: {
    id: { inList: ["driver", "mechanic", "engineer"] },
  },
}

But it gives me people who are driver OR mechanic OR engineer. I need the behavior to be driver AND mechanic AND engineer.

System Information

Additional Context

I defined the filters with FilterLookup

Upvote & Fund

Fund with Polar

bellini666 commented 4 months ago

As we discussed the other day, this is something that strawberry doesn't support, meaning you have to rely on custom filtering for this.

Going to close this for now

pfcodes commented 4 months ago

Leaving this comment as a record for anyone that might be coming from Graphene/django-filters. This type of filtering behavior is known as a conjoined filter. I'll probably make a feature request on Strawberry to support it.