`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)
| 6738 | /// the wire-carried subgraph (emit_dot/emit_html stay client-side — pure |
| 6739 | /// presentation) and writes/opens the output the same way. |
| 6740 | pub 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(), |
no test coverage detected