Querying the Graph

Lesson 3 · Learn Graphify · ~10 minutes

You've built a graph. Now learn to ask it the right questions — both from the CLI and from inside an AI session.

Win

After this lesson, you'll know how to use graphify path and graphify explain to answer structural questions without reading source files, and how to phrase prompts that leverage graph context.

Two Query Modes

Graphify gives you two ways to query:

ModeWhen to useCommand
CLI queriesQuick lookup outside an AI sessiongraphify path, graphify explain
AI-assistedComplex questions during developmentPrompt the agent with graph loaded

CLI: Finding Paths

The path command finds the shortest connection between two nodes in your graph:

graphify path "BaseTestCase" "execute_command"

This returns a chain of nodes and edges showing how those two entities connect — through imports, inheritance, or calls. Use it when you want to understand coupling between modules without reading intermediate files.

# Output example:
# BaseTestCase → (inherits) → UpdateTestCase → (calls) → execute_command
Note

Node names must match what tree-sitter extracted. Use the graph visualization (graph.html) or GRAPH_REPORT.md to find exact names if you're unsure.

CLI: Explaining Nodes

The explain command gives a plain-language description of a node and its immediate neighbors:

graphify explain "assertResult"

This shows what calls the node, what it calls, what it imports, and what community it belongs to. Think of it as a focused "tell me about this thing" without opening the source file.

AI-Assisted Queries

When the graph is loaded in a Kiro CLI or Claude Code session, you can ask structural questions that the agent answers from the graph rather than grepping files:

Good vs. Bad Queries

The graph answers structural questions well. It cannot answer behavioral questions (what does this code actually do at runtime).

Good (structural)Bad (behavioral)
"What calls execute_command?""What does execute_command return when the query fails?"
"Show all test files using assertResult""Which assertions pass on DocumentDB but fail on MongoDB?"
"What's the inheritance chain for UpdateTestCase?""How long does the test suite take to run?"
Key Insight

The graph replaces discovery, not understanding. Once the agent knows which files matter (from the graph), it still reads those files to understand behavior. The savings come from not reading the other 400 files.

Prompt Patterns That Work

These prompt shapes get the most out of graph context:

# "Show me the shape" — asks for structure, not implementation
"What's the dependency graph around the test runner?"

# "Find similar" — leverages community clustering
"What other files are in the same community as test_min_comparisons.py?"

# "Trace the path" — follows edges
"How does a test case get from BaseTestCase to an actual MongoDB command?"

# "What's connected" — neighborhood exploration
"What are the 5 most-connected nodes in the graph?"

Verify Your Understanding

When should you use graphify path instead of asking the AI agent?

Which question type is the graph not good at answering?

Do This Now

  1. Run graphify explain on the most important class in your project
  2. Run graphify path between two entities you know are related
  3. Start an AI session with graph context and ask a structural question
  4. Notice: did the agent answer from the graph or did it still read files?