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

Function query_neighbors

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

`atomic vault query neighbors` over QueryGraph (Neighbors) — every form: `-d` rides the request's depth, the wire's KGNode/KGEdge carry the full domain fields, and the JSON serializes the same subgraph shape the local body emits. The plain render matches the local listing (the Nodes/Edges sections and their counts).

(args: &super::query::QueryNeighbors)

Source from the content-addressed store, hash-verified

3142/// shape the local body emits. The plain render matches the local
3143/// listing (the Nodes/Edges sections and their counts).
3144pub fn query_neighbors(args: &super::query::QueryNeighbors) -> CliResult<bool> {
3145 let Some(session) = Service::open()? else {
3146 return Ok(false);
3147 };
3148 let (node_id, depth) = (args.node_id.clone(), args.depth);
3149 let response = session.query_graph(pb::QueryGraphRequest {
3150 repository: Some(session.reference.clone()),
3151 limit: 0,
3152 query: Some(pb::query_graph_request::Query::Neighbors(
3153 pb::NeighborsQuery {
3154 node_id,
3155 incoming: None,
3156 depth: Some(depth as u32),
3157 },
3158 )),
3159 view: None,
3160 })?;
3161 let nodes = response
3162 .nodes
3163 .iter()
3164 .map(kg_node_domain)
3165 .collect::<Vec<_>>();
3166 let edges = response
3167 .edges
3168 .iter()
3169 .map(kg_edge_domain)
3170 .collect::<CliResult<Vec<_>>>()?;
3171 if args.json {
3172 let subgraph = atomic_core::pristine::vault::KgSubgraph { nodes, edges };
3173 println!("{}", serde_json::to_string_pretty(&subgraph).unwrap());
3174 return Ok(true);
3175 }
3176 if nodes.is_empty() {
3177 println!("No neighbors found for '{}'.", args.node_id);
3178 return Ok(true);
3179 }
3180 println!("Nodes ({}):", nodes.len());
3181 for node in &nodes {
3182 let summary = node.summary.as_deref().unwrap_or("");
3183 let summary_display = if summary.is_empty() {
3184 String::new()
3185 } else {
3186 format!(" {}", super::query::truncate_display(summary, 50))
3187 };
3188 println!(
3189 " [{}] {}{}",
3190 atomic_core::kg::ontology::compact(node.primary_type()),
3191 node.id,
3192 summary_display
3193 );
3194 }
3195 println!("\nEdges ({}):", edges.len());
3196 for edge in &edges {
3197 println!(
3198 " {} \u{2192}[{}]\u{2192} {}",
3199 edge.from_id, edge.kind, edge.to_id
3200 );
3201 }

Callers 1

runMethod · 0.85

Calls 5

openFunction · 0.50
cloneMethod · 0.45
query_graphMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected