GraphQL

Tutorial 4 - Challenge Answers

5min
in our tutorial 4 challenge, we asked you to write a query which returned items matching multiple filter rules here's a possible solution prerequisites this article shows the answers to a challenge if you've not had a go at the challenge yet, we'd recommend you head there first about graphql optional read more about graphql and when it might be best used introduction last time, we asked you to write a single query which utilised a combination of filters to find records which meet these criteria they are module items they are enabled they have already been released they have not yet expired they have a `weighting` between 1 and 3 they have a meta title they fall into the posters category this challenge required you to modify and combine the queries we'd already looked at if you were able to match at least some of the criteria, good work challenge answers to find the category id for the posters category one way to do it would have been to go to the siteglide admin after that, it was a case of combining what you'd learned so far to add multiple filters to a query query webapps missing meta descriptions { records( page 1 per page 2000 filter { table {starts with "module "} properties \[ { name "meta title", exists true } { name "enabled", value boolean true} { name "release date", range { lte "1582108820" }} { name "expiry date", range { gt "1582108820" }} { name "weighting", range { gte "1", lte "3" } } { name "meta title", exists true } { name "category array", value in \["158197"] } ] } ) { total pages results { table properties } } } notes for the range of weighting we've added a gte and lte setting, in order to demonstrate the possibility this is not really necessary as there won't be values less than 0, but it's not a bad idea to rule these out, should data be entered incorrectly the category array id may be different from one site to another check your site's category id in the admin explorer unfortunately, as mentioned last time, explorer does not yet support arrays, so it's not possible to show an explorer demo for this challenge next time it's time for the real thing! we'll look at how you can save your graphql query in a file and use liquid to run it on a website page let's go!