Omnigraph
Queries

Filtering

Apply property predicates, sort results, and limit output.

Filtering narrows query results using predicates on properties, controls output order with order, and caps the number of rows with limit.

Comparison predicates

Apply predicates to bound variables using standard comparison operators:

query young_people() {
    match {
        $p: Person
        $p.age < 30
    }
    return { $p.name, $p.age }
}

Supported operators: =, !=, >, <, >=, <=.

Combining predicates

All predicates in a match block are conjunctive (AND). Every condition must be true:

query age_range() {
    match {
        $p: Person
        $p.age >= 25
        $p.age <= 40
    }
    return { $p.name, $p.age }
}

Negation blocks

Use not { } to exclude results that match a pattern:

query unemployed() {
    match {
        $p: Person
        not {
            $p worksAt $_
        }
    }
    return { $p.name }
}

Filtering on traversal targets

Combine traversal patterns with predicates on the target node:

query young_friends($name: String) {
    match {
        $p: Person { name: $name }
        $p knows $f
        $f.age < 30
    }
    return { $f.name, $f.age }
}

Ordering results

The order block sorts results by one or more keys. Use asc (ascending) or desc (descending):

query people_by_age() {
    match {
        $p: Person
    }
    return { $p.name, $p.age }
    order { $p.age desc }
}

Multiple sort keys

Separate multiple keys with commas. Rows are sorted by the first key, then ties are broken by the second, and so on:

query sorted_people() {
    match {
        $p: Person
    }
    return { $p.name, $p.age }
    order { $p.age desc, $p.name asc }
}

Ordering by aggregated values

You can order by an aggregate alias defined in the return block:

query busiest_companies() {
    match {
        $p: Person
        $p worksAt $c
    }
    return { $c.name, count($p) as employee_count }
    order { employee_count desc }
}

Limit

Cap the number of returned rows with limit:

query top_five_oldest() {
    match {
        $p: Person
    }
    return { $p.name, $p.age }
    order { $p.age desc }
    limit 5
}
omnigraph read ./repo.omni \
    --query queries.gq \
    --name top_five_oldest \
    --json
[
  { "name": "Eve", "age": 58 },
  { "name": "Frank", "age": 52 },
  { "name": "Grace", "age": 47 },
  { "name": "Hank", "age": 45 },
  { "name": "Ivy", "age": 41 }
]

On this page