graflo.db.traversal¶
Backend-neutral multi-hop traversal, composed from single-hop primitives.
Every backend that can answer fetch_edges gets correct multi-hop semantics
from this module, in one shape: a
:class:~graflo.architecture.graph_types.container.GraphContainer. Backends with
a native multi-hop query override :meth:Connection.graph_neighbors for a single
round trip, and the conformance suite asserts the override agrees with this
default rather than merely "returning something".
Direction is decided per edge, not per request: an edge declared
directed=False is followed both ways whatever the caller asked for, and a
backend that physically cannot follow the requested direction fails loudly
before any query runs, rather than returning a partial neighbourhood.
bfs_neighbors(conn, *, anchor_type, anchor_key, hops=1, direction=EdgeDirection.OUT, edge_types=None, filters=None, limit=None, schema=None)
¶
Breadth-first neighbourhood around one anchor, as a GraphContainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection
|
Live connection. Only |
required |
anchor_type
|
str
|
Logical vertex type of the anchor. |
required |
anchor_key
|
str | dict[str, Any]
|
Anchor identity value, or a field mapping to resolve. |
required |
hops
|
int
|
Maximum hop distance, at least 1. |
1
|
direction
|
EdgeDirection
|
Orientations followed from each frontier vertex. |
OUT
|
edge_types
|
Sequence[str] | None
|
Restrict to these logical relation names. |
None
|
filters
|
Any | None
|
Optional edge filter, rendered per backend dialect. |
None
|
limit
|
int | None
|
Maximum accumulated edges. Defaults to |
None
|
schema
|
Schema | None
|
Required — logical names must be resolved to storage names, or the "universal layer" leaks backend naming to the caller. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
GraphContainer |
GraphContainer
|
reached vertices and edges, deduplicated. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if hops < 1, schema is missing, or anchor_type is not declared in the schema. |
UnsupportedEdgeDirectionError
|
if a backend cannot follow an edge in the requested direction. |
Source code in graflo/db/traversal.py
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
edge_query_name(db_aware, edge, flavor)
¶
The identifier a backend's read path uses for edge.
Backends name edge types in incompatible ways, and no single accessor covers
them: edge_storage_name is Arango-only by construction (it builds an edge
collection name and returns None elsewhere), the Cypher family and
Nebula key on the relation type, and PostgreSQL keys on a derived table name.
Resolving that here keeps the choice in one place instead of in every caller.
Source code in graflo/db/traversal.py
normalize_edge_row(row)
¶
Reduce a backend's edge row to (properties, source key, target key).
fetch_edges predates this wave and returns whatever shape each driver
finds natural: Arango yields an edge document with _from/_to, the
Cypher family yields the driver's (start props, type, end props) triple,
PostgreSQL yields source_id/target_id columns. Normalizing here is
what lets every backend answer in one GraphContainer without changing a
read path other code already depends on.