query_graph
Execute Datalog or Cypher queries on a code graph to find patterns, nodes, edges, and attributes. Define violations to enforce code invariants.
Instructions
Execute a Datalog or Cypher query on the code graph.
Set language to "cypher" for Cypher queries (e.g., MATCH (n:FUNCTION) RETURN n.name). Default is Datalog.
Available Datalog predicates:
type(Id, Type) / node(Id, Type) - match nodes by type
edge(Src, Dst, Type) - match edges
attr(Id, Name, Value) - match node attributes (name, file, line, etc.)
gt(Val, N), lt(Val, N), gte(Val, N), lte(Val, N) - numeric comparisons
+ - negation (not)
NODE TYPES:
MODULE, FUNCTION, METHOD, CLASS, VARIABLE, PARAMETER
CALL, PROPERTY_ACCESS, METHOD_CALL, CALL_SITE
METRIC (performance metrics: value/unit/source in metadata, OBSERVES → MODULE)
ISSUE (analysis problems: category/severity/message in metadata, CONTAINS ← MODULE)
http:route, http:request, db:query, socketio:emit, socketio:on
EDGE TYPES:
CONTAINS, CALLS, DEPENDS_ON, ASSIGNED_FROM, INSTANCE_OF, PASSES_ARGUMENT
OBSERVES (METRIC → MODULE, links performance metric to observed file)
EXAMPLES: violation(X) :- node(X, "MODULE"). violation(X) :- node(X, "FUNCTION"), attr(X, "file", "src/api.js"). violation(X) :- node(X, "CALL"), + edge(X, _, "CALLS"). violation(F, Ms) :- node(M, "METRIC"), attr(M, "name", "parse_ms"), attr(M, "value", Ms), gte(Ms, 500), edge(M, Mod, "OBSERVES"), attr(Mod, "file", F).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Datalog query (must define violation/1 predicate) or Cypher query (when language is "cypher"). | |
| language | No | Query language: "datalog" (default) or "cypher" | |
| limit | No | Max results to return (default: 10, max: 500) | |
| offset | No | Skip first N results for pagination (default: 0) | |
| explain | No | Show step-by-step query execution to debug empty results | |
| count | No | When true, returns only the count of matching results instead of the full result list |