Path Queries

How to perform path queries using WOQL

To use this How-To, first clone the Star Wars demo into your team on TerminusCMS. You will then have full access to the data needed for this tutorial

How to use path

TerminusCMS gives us path queries that allow us to express chains of relationships succinctly.

The path keyword enables you to find a path through the graph traversing intermediate edges. An example would be finding a group of individuals who have at some point shared a vehicle as pilots, or piloted another vehicle that was shared with someone. This is a transitive relationship and will explore the entire graph.

For instance

let v = Vars("person1", "person2");
path(v.person1, "(<pilot,pilot>)+", v.person2)

This path means we follow the pilot field backward (because of the < arrow), to the vehicle of which the person is a pilot and then follow it forwards pilot> any number of times but at least once which is what the + means.

The path itself can also be returned by adding another field, as so:

let v = Vars("person1", "person2", "path");
path(v.person1, "(<pilot,pilot>)+", v.person2, v.path)

This can be inspected to understand the manner in which we got from person1 to person2.

Last updated