graflo.db.cypher.traversal¶
Native variable-length traversal for the Cypher family.
Neo4j, Memgraph and FalkorDB all express a bounded neighbourhood as a single
variable-length pattern, so one builder serves all three — the same reason
:func:cypher_rel_pattern is shared.
A native override is not only a performance choice here. fetch_edges on this
family returns RETURN r, and a driver renders a bare relationship without its
endpoints, so the generic breadth-first default has nothing to walk to. Returning
the reached nodes directly is the only way the question is answerable at all.
cypher_graph_neighbors(conn, *, vertex_type, key, hops, direction, edge_types, limit, schema, run)
¶
Run a bounded neighbourhood query and shape it as a GraphContainer.
Shared by Neo4j, Memgraph and FalkorDB; each supplies run, which is the only thing that differs between their drivers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
The live connection, for flavor-aware name resolution. |
required |
vertex_type
|
str
|
Logical anchor type. |
required |
key
|
str | dict[str, Any]
|
Anchor identity value, or a single-field mapping. |
required |
hops
|
int
|
Maximum hop distance. |
required |
direction
|
EdgeDirection
|
Orientation followed from the anchor. |
required |
edge_types
|
Sequence[str] | None
|
Logical relation names to restrict to. One pattern is issued per allowed relation, since a variable-length pattern takes a single relationship type. |
required |
limit
|
int | None
|
Maximum reached nodes. |
required |
schema
|
Schema | None
|
Required for logical -> storage naming. |
required |
run
|
Callable[[str], list[dict[str, Any]]]
|
Executes a query string and returns rows as dicts. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GraphContainer |
GraphContainer
|
reached vertices, keyed by logical type. |
Source code in graflo/db/cypher/traversal.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
cypher_neighbors_query(*, anchor_label, anchor_id, anchor_key_field='id', edge_type, far_label, direction, hops, limit)
¶
Render a bounded neighbourhood query.
Returns the reached nodes and their distance, deduplicated. DISTINCT is
load-bearing: a graph with a cycle reaches the same node by several paths,
and without it the row count grows with path multiplicity rather than with
neighbourhood size.