fraiseql_core/schema/dependency_graph/
graph.rs1use std::collections::{HashMap, HashSet};
4
5#[derive(Debug, Clone)]
12pub struct SchemaDependencyGraph {
13 pub(super) outgoing: HashMap<String, HashSet<String>>,
15 pub(super) incoming: HashMap<String, HashSet<String>>,
17 pub(super) all_types: HashSet<String>,
19 pub(super) root_types: HashSet<String>,
21}
22
23impl SchemaDependencyGraph {
24 #[must_use]
26 pub fn dependencies_of(&self, type_name: &str) -> Vec<String> {
27 self.outgoing
28 .get(type_name)
29 .map(|deps| {
30 let mut v: Vec<_> = deps.iter().cloned().collect();
31 v.sort();
32 v
33 })
34 .unwrap_or_default()
35 }
36
37 #[must_use]
39 pub fn dependents_of(&self, type_name: &str) -> Vec<String> {
40 self.incoming
41 .get(type_name)
42 .map(|refs| {
43 let mut v: Vec<_> = refs.iter().cloned().collect();
44 v.sort();
45 v
46 })
47 .unwrap_or_default()
48 }
49
50 #[must_use]
52 pub fn all_types(&self) -> Vec<String> {
53 let mut types: Vec<_> = self.all_types.iter().cloned().collect();
54 types.sort();
55 types
56 }
57
58 #[must_use]
60 pub fn type_count(&self) -> usize {
61 self.all_types.len()
62 }
63
64 #[must_use]
66 pub fn has_type(&self, type_name: &str) -> bool {
67 self.all_types.contains(type_name)
68 }
69}