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

Function query_graph

atomic-cli/src/commands/rpc.rs:6740–6843  ·  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

6738/// the wire-carried subgraph (emit_dot/emit_html stay client-side — pure
6739/// presentation) and writes/opens the output the same way.
6740pub fn query_graph(args: &super::query::QueryGraph) -> CliResult<bool> {
6741 let Some(session) = Service::open()? else {
6742 return Ok(false);
6743 };
6744 let request = pb::QueryGraphRequest {
6745 repository: Some(session.reference.clone()),
6746 limit: 0,
6747 query: Some(pb::query_graph_request::Query::GraphSlice(
6748 pb::GraphSliceQuery {
6749 node_ids: Vec::new(),
6750 max_depth: None,
6751 query: Some(args.query.clone()),
6752 seed_limit: Some(args.limit as u32),
6753 depth: Some(args.depth.min(2) as u32),
6754 kinds: Some(args.kinds.clone()),
6755 changes_per_seed: Some(args.changes_per_seed as u32),
6756 max_nodes: args.max_nodes.map(|max| max as u32),
6757 },
6758 )),
6759 view: None,
6760 };
6761 let response = session.query_graph(request)?;
6762 let nodes = response
6763 .nodes
6764 .iter()
6765 .map(kg_node_domain)
6766 .collect::<Vec<_>>();
6767 let edges = response
6768 .edges
6769 .iter()
6770 .map(kg_edge_domain)
6771 .collect::<CliResult<Vec<_>>>()?;
6772 if nodes.is_empty() && !args.json {
6773 eprintln!("No results for {:?} (kinds: {}).", args.query, args.kinds);
6774 return Ok(true);
6775 }
6776 // Cap note: the wire carries only the final set; the note's collected
6777 // count is the final length when a cap applied (0 = uncapped).
6778 let capped = nodes.len() >= args.max_nodes.unwrap_or(usize::MAX);
6779 if capped {
6780 eprintln!(
6781 "Note: {} nodes collected, showing top {}. Use --max-nodes to adjust.",
6782 nodes.len(),
6783 args.max_nodes.unwrap_or(nodes.len()),
6784 );
6785 }
6786 if args.json {
6787 let output = serde_json::json!({
6788 "nodes": nodes,
6789 "edges": edges,
6790 });
6791 let json_str = serde_json::to_string_pretty(&output).unwrap();
6792 if let Some(ref path) = args.output {
6793 std::fs::write(path, &json_str)
6794 .map_err(|e| CliError::Internal(anyhow::anyhow!("write failed: {e}")))?;
6795 eprintln!(
6796 "Wrote {} nodes, {} edges to {}",
6797 nodes.len(),

Callers 1

runMethod · 0.85

Calls 13

GraphSliceClass · 0.85
emit_dotFunction · 0.85
emit_htmlFunction · 0.85
temp_dirFunction · 0.85
openFunction · 0.50
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