Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by tags #5

Open
yarl opened this issue Apr 7, 2018 · 4 comments
Open

Filter by tags #5

yarl opened this issue Apr 7, 2018 · 4 comments

Comments

@yarl
Copy link

yarl commented Apr 7, 2018

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"})
}
@aheinze
Copy link
Member

aheinze commented Apr 8, 2018

please try

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

@gryphonmyers
Copy link

gryphonmyers commented Sep 6, 2019

@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 Filter by date #17 , any keys prefixed by $ character are failing in the graphql editor: "Syntax Error: Expected Name, found $" How can we get around this?

@aheinze
Copy link
Member

aheinze commented Sep 6, 2019

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

@gryphonmyers
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants