Query Engine¶
This document describes Graphite's fluent query engine. Queries start from engine.query and return a chainable QueryResult object.
The entry point is the QueryBuilder, which allows starting a query from a node type.
Starting a Query¶
You can start a query from a node type:
Accessing engine.query.Person returns all nodes whose type is Person.
To start from all nodes:
If the node type does not exist, a NotFoundError is raised.
Filtering¶
where()¶
Filters nodes using either:
- A string condition
- A callable (lambda)
String Condition¶
Supported operators:
==or=!=><>=<=
Date fields are parsed using YYYY-MM-DD format.
Lambda Condition¶
If the condition fails to evaluate, a ConditionError is raised.
with_type()¶
Filter by exact node type:
with_fields()¶
Filter nodes that contain specific fields:
Traversal¶
Traversal moves across relations and returns connected nodes.
Outgoing¶
Equivalent to:
from graphite import Direction
engine.query.Person.traverse("WORKS_AT", direction=Direction.OUTGOING)
Incoming¶
Both Directions¶
If no relation type is provided, all relation types are considered.
Traversal returns a new QueryResult containing:
- Connected nodes
- Traversed relations
Result Control¶
limit()¶
paginate()¶
distinct()¶
Removes duplicate nodes:
order_by()¶
Aggregation¶
count()¶
sum()¶
Non-numeric values are ignored.
avg()¶
min() / max()¶
group_by()¶
Returns a dictionary mapping field values to lists of nodes.
Combining Queries¶
union()¶
May produce duplicates; use .distinct() if necessary.
exclude()¶
intersect()¶
Tip
This query is implemented for complex use cases; for simple cases, it is recommended to use .where() chains:
Mutations¶
Important
"Mutation" queries directly apply their effects to the engine. To remove findings from the query (and not actually
delete nodes and relationships from the engine), you can use .exclude() (ramove) and .intersect() (select).
set()¶
Updates field values on all result nodes:
Changes are applied directly to the engine.
If a field does not exist, a NotFoundError is raised.
remove()¶
Removes result nodes:
remove_relations()¶
Removes relations in the current result:
Accessing Results¶
Get Nodes¶
First Result¶
Get IDs¶
Get Relations¶
Execution Model¶
- Queries are evaluated eagerly.
- Each chained call returns a new
QueryResult. - Nodes and relations are stored in memory.
- Mutating operations (
set,remove) modify engine state directly.
Summary¶
The Query Engine provides:
- Type-based entry points (
engine.query.Type) - Chainable filtering and traversal
- Aggregation and grouping
- Query composition (union, intersect, exclude)
- Direct mutation capabilities
It is designed to provide a concise, expressive interface for graph exploration while preserving type constraints enforced by the engine.