Docs / design / gql-design · Edit on GitHub

Graph Query Language (GQL) — Engineering Design

Cypher-like graph queries over the indexed knowledge graph: 30+ node and edge types, macros, explain plans, and HTTP access via serve.

Package metagraph — graph exploration (gbuilder)

Figure 1: Graph Visualization tab — package metagraph (WebGL), community colors, and drill-down into member functions. CLI gql queries the same underlying graph.

Dashboard shell with graph tab (gbuilder)

Figure 2: Full dashboard context — stat cards, tab bar, and graph exploration surface.


1. Goals

GoalHow
Precise structural queriesMATCH patterns over typed nodes/edges
Fast inventoryNamed macros (all_functions, call_chain, …)
Agent automation-f json rows + POST /api/query
Explainability--explain optimization plan

Note: export --query uses filter syntax (name:Foo, type:Function, all) — not full GQL. Use gql for MATCH patterns.


2. Architecture overview

flowchart TB
  subgraph index["discover"]
    SNAP[graph.snapshot.bin]
    SNAP --> BACK[MemoryBackend / SnapshotNodeStore]
  end

  subgraph gql["GQL pipeline"]
    PARSE[parser]
    OPT[QueryOptimizer]
    EXEC[QueryExecutor]
    PARSE --> OPT --> EXEC
  end

  subgraph surfaces["Surfaces"]
    CLI[rgctl gql]
    HTTP[POST /api/query]
    WASM[WASM expand / list_nodes]
  end

  BACK --> gql
  gql --> CLI
  gql --> HTTP
  BACK --> WASM

3. Query language (subset)

MATCH (n:Function) WHERE n.name LIKE '*Service*' RETURN n LIMIT 20
MATCH (a:Function)-[:CALLS*1..3]->(b:Function) RETURN a, b
MATCH (n:Class) WHERE n.qualified_name = 'com.example.Foo' RETURN n

n.name is the simple/bare name; use n.qualified_name for language FQNs (e.g. Java package paths).

Macros (positional query ignored when --macro-name set):

MacroPurpose
all_functionsFunction inventory
direct_callsCall edges
call_chainChains up to 3 hops

4. Rust implementation map

ComponentPath
Parser / ASTcrates/rgctl-gql/src/parser.rs, ast.rs
Optimizercrates/rgctl-gql/src/optimizer.rs
Executorcrates/rgctl-gql/src/executor.rs
Macroscrates/rgctl-gql/src/macros.rs
CLIsrc/cli/gql.rs
HTTPsrc/cli/http_serve.rs (/api/query)

5. Dashboard implementation

There is no dedicated GQL tab. Exploration maps to:

DashboardGQL equivalent
Graph metagraph + drill-downMATCH on Function / Calls, export
Functions tableall_functions macro
Query Guide tabCopy-paste CLI workflows (guideCliWorkflows.ts)

6. CLI and HTTP usage

rgctl discover .
rgctl gql 'MATCH (n:Function) RETURN n LIMIT 5'
rgctl -f json gql --macro-name all_functions unused
rgctl gql --explain 'MATCH (n:Function) WHERE n.name = "Foo" RETURN n'

rgctl serve --open
curl -sS -X POST http://127.0.0.1:8080/api/query \
  -H 'Content-Type: application/json' \
  -d '{"macro":"all_functions"}' | jq '.count'

See http-api.md.

Virtual communities (analysis overlay)

Communities are not stored in graph.snapshot.bin. After discover, gql / /api/query join .rgctl/analysis_results.bin:

PatternMeaning
MATCH (c:Community) RETURN cList named communities (macro: all_communities)
WHERE f.community_id = '12'Filter functions by assignment
c.label / member_countProperties on virtual community nodes

Labels are heuristic; see community-query-and-naming-plan.md.


7. Testing

LayerLocation
GQL crate testscrates/rgctl-gql/src/
CLI subprocesstests/cli_output/all_commands_sanity.rs
Query Guide validationdashboard/scripts/validate-guide-cli-gbuilder.sh

Screenshots: capture-design-screenshots.mjsdocs/images/design/gql/.


8. Related docs