CockpitQL
CockpitQL copied to clipboard
Filter by tags
I try to filter collection by tags fieldtype, but as a result I always see empty array. I tried to use code below with few other variants, but no success.
{
collection(name:"posts", filter:{published:true, tags:"news"})
}
please try
{
collection(name:"posts", filter:{published:true, tags:{$has:"news"}})
}
@aheinze, can you clarify a couple things for me:
-
What is the expected format of the filter argument in this context? I am used to passing mongo queries into cockpit, but I don't recognize "$has" as a mongo operator. Is this some other graphql-specific API? I can't find documentation of "$has" anywhere.
-
As described by #17 , any keys prefixed by $ character are failing in the graphql editor: "Syntax Error: Expected Name, found $" How can we get around this?
@gryphonmyers
- this was misleading
$has
is only available when you're using MongoLite (SQLite) - you need to use graphql with variables, eg:
query posts($filter: JsonType) {
collection(name:"posts", filter:$filter)
}
with variables:
"filter":{"published": true, "date":{"$lt": "2019-03-01"}
@aheinze Awesome! Thanks for the explanation. At some point this should go in the documentation