CockpitQL icon indicating copy to clipboard operation
CockpitQL copied to clipboard

Filter by tags

Open yarl opened this issue 6 years ago • 4 comments

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"})
}

yarl avatar Apr 07 '18 22:04 yarl

please try

{
  collection(name:"posts", filter:{published:true, tags:{$has:"news"}})
}

aheinze avatar Apr 08 '18 20:04 aheinze

@aheinze, can you clarify a couple things for me:

  1. 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.

  2. 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 avatar Sep 06 '19 18:09 gryphonmyers

@gryphonmyers

  1. this was misleading $has is only available when you're using MongoLite (SQLite)
  2. 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 avatar Sep 06 '19 22:09 aheinze

@aheinze Awesome! Thanks for the explanation. At some point this should go in the documentation

gryphonmyers avatar Sep 18 '19 22:09 gryphonmyers