If you have a checkbox or multi-select field that you need to filter for in the GraphQL API you will get no results.
For example if I run this query:
query Employees ($employeeGroups: [QueryArgument]) {
entries (section: "employees", employeeGroups: $employeeGroups) {
... on employees_employees_Entry {
title
employeeGroups
}
}
}
With the following variables:
{
"employeeGroups": "board"
}
I get the following results:
{
"data": {
"entries": []
}
}
Although, if I'm not supplying a variable I get the following results (as expected):
{
"data": {
"entries": [
{
"title": "Firstname Surname",
"employeeGroups": [
"board"
]
}
]
}
}
The above result is what I'm looking to get when supplying a variable for employeeGroups with the board value.
I have also tried to supply an array as the employeeGroups variable but it makes no difference, although that's expected as the description for a QueryArgument states: It can be both an integer or a string..
Perhaps array support should be added for checkboxes and multi-select field types because these fields are multiple choice?
As per the element query docs, you should be setting it like this:
{
"employeeGroups": "*\"board\"*"
}
I agree, though, that it is incredibly awkward. We'll discuss how to better address this as I have a few ideas.
Great, that would be awesome 👍
Just pushed an update to Checkboxes and Multi-select fields for the next Craft 3.4 release. The following parameter syntaxes are now supported as of 3.4.6:
| Value | Fetches elements…
| - | -
| "foo" | with a foo option selected.
| "not foo" | without a foo option selected.
| ["foo", "bar"] | with foo or bar options selected.
| ["and", "foo", "bar"] | with foo and bar options selected.
Great work! This makes it infinitely more logical to use! 🥇
Craft 3.4.6 is out now with this change.
Most helpful comment
Just pushed an update to Checkboxes and Multi-select fields for the next Craft 3.4 release. The following parameter syntaxes are now supported as of 3.4.6:
| Value | Fetches elements…
| - | -
|
"foo"| with afoooption selected.|
"not foo"| without afoooption selected.|
["foo", "bar"]| withfooorbaroptions selected.|
["and", "foo", "bar"]| withfooandbaroptions selected.