Allow multiple selections does not work in views filter criteria

Created on 25 March 2025, about 1 month ago

I get 'Argument #1 ($item) must be of type array, string given' error for the below query when I use 'Allow multiple selections' in the location tags view (graphql) filter.

query {
graphqlExampleGraphql1(filter: {
field_location_tags_target_id: ["Boxing Ring", "Offices"]
}) {
results {
... on NodeLocation {
title
}
}
}
}

🐛 Bug report
Status

Active

Version

2.3

Component

Code

Created by

🇬🇧United Kingdom hasozduru

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @hasozduru
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Can you attach an export or screenshot of your view please. Need to recreate the view to test.

  • 🇦🇺Australia almunnings Melbourne, 🇦🇺

    Under Filter Criteria:

    • Click "Settings" next to "Your filter"
    • Change "Selection type" to "Dropdown" (This should stop your error)
    • Click Apply

    Under Filter Criteria:

    • Click "Your filter"
    • Enable "Reduce duplicates"
    • Enable "Allow multiple selections"

    So now, when querying, you can use an array.
    But you need to use the actual IDs. Not the labels.

    To get the label IDs, in your query can use the filters field to list out all your filters. So probably on initial load of your view, you can get that list of filters, or put it in state somewhere else? Or just hard code it, up to your app? I'd probably opt to run a query for filters.

    {
      testViewGraphql1 {
        filters {
          id
          options
        }
      }
    }
    

    Example result

    {
      "data": {
        "testViewGraphql1": {
          "filters": [
            {
              "id": "field_tags_target_id",
              "options": {
                "1": "AA",
                "2": "BB"
              }
            }
          ]
        }
      }
    }
    

    Then use those IDs to query:
    Example query:

    {
      testViewGraphql1(filter:{
        field_tags_target_id: ["1", "2"]
      }) {
        results {
          __typename
        }
      }
    }
    

    Example result

    {
      "data": {
        "testViewGraphql1": {
          "results": [
            {
              "__typename": "NodePage"
            },
            {
              "__typename": "NodePage"
            },
            {
              "__typename": "NodePage"
            }
          ]
        }
      }
    }
    
  • 🇦🇺Australia almunnings Melbourne, 🇦🇺
  • 🇬🇧United Kingdom hasozduru

    Thanks very much almunnings.

Production build 0.71.5 2024