这是indexloc提供的服务,不要输入任何密码
Skip to content

Advanced filtering in PaginatedList only works as long as the attributes are distinct #3267

@lz-jf

Description

@lz-jf

Describe the bug
Advanced filtering in PagenatedList queries does not return any items as soon as the same attribute is filtered by more than once.
The most common use case is probably filtering by facetValueId (which strangely also is available on the shop API, but that's another topic). But using it twice within a _and or _or operator leads to no results. It does work as expected in the search query but imo the provided filter on the products query should work as you would it expect it to.

To Reproduce
Steps to reproduce the behavior:

  1. Setup a vanilla Vendure installation with the provided sample data.
  2. Run the following query on the admin API:
query Products {
    products(options: { 
        filter: { 
            _and: [
                {
                    facetValueId: {
                        eq: "34"
                    }
                }
            ]
        }
    }) {
        totalItems
        items {
            name
        }
    }
}
  1. This should return 11 items
  2. Now add a second facetValue to the filter:
query Products {
    products(options: { 
        filter: { 
            _and: [
                {
                    facetValueId: {
                        eq: "34"
                    }
                },
                {
                    facetValueId: {
                        eq: "37"
                    }
                }
            ]
        }
    }) {
        totalItems
        items {
            name
        }
    }
}
  1. No items are returned even though there are products matching both facetValues

Expected behavior
The latter query should return 2 items.

Environment (please complete the following information):

  • @vendure/core version: 3.1.0
  • Nodejs version: 20.11.0
  • Database (mysql/postgres etc): postgres

Additional context
This can be recreated in the admin-ui by filtering by facet values Category:Furniture (34) and Color:Wood (37). It works in the admin ui because here two subsequent requests are made instead of one with both facetValues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    📅 Planned

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions