Match
Bind variables to nodes, filter by type and property values, and combine patterns.
The match block is where you describe the graph patterns you want to find. Every pattern binds a variable to a node or edge, optionally filtering by type and property values.
Binding variables
Bind a variable to a node type with $variable: Type:
query all_people() {
match {
$p: Person
}
return { $p.name, $p.age }
}The variable $p is bound to every Person node in the graph.
Inline property matching
Filter nodes by exact property values inside curly braces:
query find_alice() {
match {
$p: Person { name: "Alice" }
}
return { $p.name, $p.age }
}Multiple properties narrow the match further:
query specific_person() {
match {
$p: Person { name: "Alice", age: 30 }
}
return { $p.name }
}Predicate filters
Use comparison operators on bound variables for more flexible filtering:
query older_than_thirty() {
match {
$p: Person
$p.age > 30
}
return { $p.name, $p.age }
}Comparison operators
| Operator | Meaning |
|---|---|
= | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
Operators work on numeric types (I32, I64, F32, F64), String (lexicographic), Date, and DateTime.
Combining patterns
All patterns in a match block are conjunctive (AND). Every pattern must be satisfied for a result to be returned:
query senior_at_company($company: String) {
match {
$p: Person
$c: Company { name: $company }
$p worksAt $c
$p.age >= 40
}
return { $p.name, $p.age }
}This query binds $p to a Person, binds $c to a specific Company, requires a worksAt edge between them, and filters on age — all four conditions must hold.
Using parameters in match
Parameters passed at query time substitute into the match block:
query people_named($name: String) {
match {
$p: Person { name: $name }
}
return { $p.name, $p.age }
}omnigraph read ./repo.omni \
--query queries.gq \
--name people_named \
--params '{"name": "Bob"}'[
{ "name": "Bob", "age": 32 }
]