graflo.architecture.query¶
DB-agnostic read contract: what an agent may ask of a live graph.
Layer 2. Imports filter/ and graph_types/ (layer 1) and nothing from db/ —
enforcement has to be expressible without a driver, or "enforced in core" would
mean "enforced wherever a driver happens to be imported".
Not in contract/, which is the write-side manifest at layer 3: mixing a read
contract into it would muddy a boundary the layering test already guards.
AggregateQuery
¶
Bases: GraphQuery
Count or summarise one vertex type.
Source code in graflo/architecture/query/models.py
aggregation
property
¶
function as an enum. See NeighborQuery.edge_direction.
CapExceededError
¶
Bases: ValueError
A query asked for more than a cap allows.
Carries the cap's name so the surface can say which limit was hit rather than returning a generic validation failure — an agent that is told "too many hops, max is 3" can retry; one told "invalid request" cannot.
Source code in graflo/architecture/query/caps.py
GraphQuery
¶
Bases: ConfigBaseModel
Shared envelope for every read request.
Note
There is intentionally no caps field. Caps come from
:data:HARD_CAPS and are lowered only through :meth:narrowed, so a
request body cannot raise its own ceiling.
Source code in graflo/architecture/query/models.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 | |
finish_init(caps=None)
¶
Validate against caps, defaulting to the core ceiling.
Returns:
| Type | Description |
|---|---|
Self
|
Self, so the call composes: |
Raises:
| Type | Description |
|---|---|
CapExceededError
|
Naming the cap that was exceeded. |
Source code in graflo/architecture/query/models.py
narrowed(caps)
¶
Return a copy fitted to caps, raising on anything explicitly asked for.
The split is what makes caps both enforceable and usable:
- A value the caller explicitly set above a cap raises
:class:
CapExceededError. Silently clamping it would hand back a partial answer the caller believes is complete — the failure mode this codebase already rejected for TigerGraph edge direction. - A value the caller left at its default is clamped. A policy of
max_rows=5must not 422 every request that simply did not mention a limit; that would make strict policies unusable rather than safe.
model_fields_set is what distinguishes the two, which is precisely
why it must be consulted rather than comparing against the default.
Projection is always intersected rather than raising, since an allow-list exists to hide properties: refusing the request would tell the caller which forbidden property they guessed correctly.
Source code in graflo/architecture/query/models.py
NeighborQuery
¶
Bases: GraphQuery
What is adjacent to one anchor vertex.
The instance-plane counterpart of SchemaGraph.schema_neighbors. They are
different questions and must never share a name: this one asks which rows
are adjacent, the other which types can be.
Source code in graflo/architecture/query/models.py
edge_direction
property
¶
direction as an enum, for handing to a driver.
ConfigBaseModel sets use_enum_values=True, so the stored value is
the bare string. Backends compare against EdgeDirection members, and a
string silently matches none of them — which each backend then resolves
differently, so the same query returns different neighbourhoods
depending on where it runs. Always cross the boundary through this.
NodeQuery
¶
Bases: GraphQuery
List vertices of one type, optionally filtered.
Source code in graflo/architecture/query/models.py
QueryCaps
¶
Bases: ConfigBaseModel
Ceilings a read request must fit inside.
Defaults are the core ceiling. A deployment narrows them per connection via
:meth:GraphQuery.narrowed; nothing widens them.
Source code in graflo/architecture/query/caps.py
narrow(other)
¶
Combine two cap sets, taking the stricter of each.
Narrowing is a lattice meet, not an override: a policy that tried to raise a ceiling silently becomes a no-op rather than a privilege escalation.
Source code in graflo/architecture/query/caps.py
QueryResult
¶
Bases: ConfigBaseModel
A query's answer plus the honest caveats.
Source code in graflo/architecture/query/result.py
of(container, *, caps_hit=None, elapsed_ms=0)
classmethod
¶
Build a result, deriving the element count from the container.
Source code in graflo/architecture/query/result.py
TraverseQuery
¶
Bases: GraphQuery
What is reachable from a set of anchors.
Source code in graflo/architecture/query/models.py
edge_direction
property
¶
direction as an enum. See NeighborQuery.edge_direction.