What you'll achieve By the end of this guide, you will know how to filter query results using TerminusDB's GraphQL interface.
Prerequisites: TerminusDB running on
localhost:6363with the Star Wars dataset cloned. If you haven't done this yet, follow the Explore a Real Dataset tutorial (Steps 1–2), or run:curl -u admin:root -X POST http://localhost:6363/api/clone/admin/star-wars \ -H "Content-Type: application/json" \ -H "Authorization-Remote: Basic cHVibGljOnB1YmxpYw==" \ -d '{"remote_url": "https://data.terminusdb.org/public/star-wars", "label": "Star Wars", "comment": "Star Wars dataset"}'
Using a Filter
Once you have Star Wars, you can enter into the data product and you can type the following in the GraphQL query panel:
Let's choose homeworld
Example: GraphQL
query{
People(filter: { label : { █ }}){
}
}Type Ctrl-c and you'll be given some filters which can be used to constrain the label field.
Let's choose a regex which demonstrates the fondness the creators of Star Wars had for the 'oo' sound.
Example: GraphQL
query{
People(filter:{ label : {regex: ".*oo.*"}}){
label
homeworld{
label
}
}
}This results in:
Example: JSON
{
"data": {
"People": [
{
"label": "Roos Tarpals",
"homeworld": {
"label": "Naboo"
}
},
{
"label": "Yarael Poof",
"homeworld": {
"label": "Quermia"
}
},
{
"label": "Plo Koon",
"homeworld": {
"label": "Dorin"
}
},
{
"label": "Dooku",
"homeworld": {
"label": "Serenno"
}
},
{
"label": "Sly Moore",
"homeworld": {
"label": "Umbara"
}
}
]
}
}Next steps
- Advanced filtering — combine filters with
_and,_or, and_notlogic - Limit and paginate — control how many results are returned
- Order results — sort query results by field values
- Path queries — traverse relationships across multiple hops