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

Function query_neighbors

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

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

Callers 1

runMethod · 0.85

Calls 5

openFunction · 0.85
cloneMethod · 0.45
query_graphMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected