MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / query_graph

Function query_graph

atomic-cli/src/commands/rpc.rs:6700–6803  ·  view source on GitHub ↗

`atomic query graph` over QueryGraph (GraphSlice) — the seed/expand/ filter/cap build runs handler-side; the CLI renders JSON/DOT/HTML from the wire-carried subgraph (emit_dot/emit_html stay client-side — pure presentation) and writes/opens the output the same way.

(args: &super::query::QueryGraph)

Source from the content-addressed store, hash-verified

6698/// the wire-carried subgraph (emit_dot/emit_html stay client-side — pure
6699/// presentation) and writes/opens the output the same way.
6700pub fn query_graph(args: &super::query::QueryGraph) -> CliResult<bool> {
6701 let Some(session) = Service::open()? else {
6702 return Ok(false);
6703 };
6704 let request = pb::QueryGraphRequest {
6705 repository: Some(session.reference.clone()),
6706 limit: 0,
6707 query: Some(pb::query_graph_request::Query::GraphSlice(
6708 pb::GraphSliceQuery {
6709 node_ids: Vec::new(),
6710 max_depth: None,
6711 query: Some(args.query.clone()),
6712 seed_limit: Some(args.limit as u32),
6713 depth: Some(args.depth.min(2) as u32),
6714 kinds: Some(args.kinds.clone()),
6715 changes_per_seed: Some(args.changes_per_seed as u32),
6716 max_nodes: args.max_nodes.map(|max| max as u32),
6717 },
6718 )),
6719 view: None,
6720 };
6721 let response = session.query_graph(request)?;
6722 let nodes = response
6723 .nodes
6724 .iter()
6725 .map(kg_node_domain)
6726 .collect::<Vec<_>>();
6727 let edges = response
6728 .edges
6729 .iter()
6730 .map(kg_edge_domain)
6731 .collect::<CliResult<Vec<_>>>()?;
6732 if nodes.is_empty() && !args.json {
6733 eprintln!("No results for {:?} (kinds: {}).", args.query, args.kinds);
6734 return Ok(true);
6735 }
6736 // Cap note: the wire carries only the final set; the note's collected
6737 // count is the final length when a cap applied (0 = uncapped).
6738 let capped = nodes.len() >= args.max_nodes.unwrap_or(usize::MAX);
6739 if capped {
6740 eprintln!(
6741 "Note: {} nodes collected, showing top {}. Use --max-nodes to adjust.",
6742 nodes.len(),
6743 args.max_nodes.unwrap_or(nodes.len()),
6744 );
6745 }
6746 if args.json {
6747 let output = serde_json::json!({
6748 "nodes": nodes,
6749 "edges": edges,
6750 });
6751 let json_str = serde_json::to_string_pretty(&output).unwrap();
6752 if let Some(ref path) = args.output {
6753 std::fs::write(path, &json_str)
6754 .map_err(|e| CliError::Internal(anyhow::anyhow!("write failed: {e}")))?;
6755 eprintln!(
6756 "Wrote {} nodes, {} edges to {}",
6757 nodes.len(),

Callers 1

runMethod · 0.85

Calls 13

openFunction · 0.85
GraphSliceClass · 0.85
emit_dotFunction · 0.85
emit_htmlFunction · 0.85
temp_dirFunction · 0.85
writeFunction · 0.50
cloneMethod · 0.45
query_graphMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected