Responses to the discussion on Github
Collaborator
@alexandrebodin I believe you had a way to handle this with the new complex queries but I can’t seem to find the reference. Can you describe how we use those and I can try to write documentation for it?
Maintainer
rename the OR with _or. the syntax inside of where is the same as the one described in the parameters doc here: https://strapi.io/documentation/v3.x/content-api/parameters.html#complex-queries.
Author
Thanks a lot! This worked, I initially read that part but since it was referring to REST filtering and I found the resulting query string quite complex I didn’t think of applying it to GraphQL. It would be amazing if you wrote documentation for it @derrickmehaffy so it can be clearer.
@aalasolutions how abount AND
?
i try the following query, it did not work:
query {
products(where:{ _and: [ { labels: { name:"category",value: "blade" }},
{ labels: { name:"category",value: "featured" }}]}) {
name
unique_name
labels {
name
}
}
}
Thanks,
my related issue is from graphcool - GraphQL: Filter data in an array - Stack Overflow, i use a category like a tag for product.
[
wujun4code](wujun4code (Wu Jun) · GitHub)75d ago
my rest api request is :
curl --location --request GET 'localhost:1337/products?_where[0][labels.name]=category&_where[1][labels.value]=blade&_where[2][labels.name]=category&_where[3][labels.value]=featured'
it works well.
Maintainer
THere are no and this is implicit in the _where
You can add
query {
products(where:{ _where: [ { labels: { name:"category",value: "blade" }},
{ labels: { name:"category",value: "featured" }}]}) {
name
unique_name
labels {
name
}
}
}
@alexandrebodin but i got the following error:
{
"errors": [
{
"message": "Cast to ObjectId failed for value \"{ name: 'category', value: 'pupular-items' }\" at path \"labels\" for model \"product\"",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"products"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"stringValue": "\"{ name: 'category', value: 'pupular-items' }\"",
"kind": "ObjectId",
"value": {
"name": "category",
"value": "pupular-items"
},
"path": "labels",
"reason": {}
}
}
}
],
"data": {
"products": null
}
}