From 9cdf3ef8b8efcdd5b1c5934a94c6312c7087564e Mon Sep 17 00:00:00 2001 From: Bnchi <77180905+bnchi@users.noreply.github.com> Date: Wed, 5 Jun 2024 12:58:56 +0300 Subject: [PATCH] fix(config): overflow issue in get_all_used_type_names in case of cyclic type (#2109) --- src/core/config/config.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/core/config/config.rs b/src/core/config/config.rs index d3dc6882cf..ef2e003fa1 100644 --- a/src/core/config/config.rs +++ b/src/core/config/config.rs @@ -790,6 +790,10 @@ impl Config { } while let Some(type_name) = stack.pop() { if let Some(typ) = self.types.get(&type_name) { + if set.contains(&type_name) { + continue; + } + set.insert(type_name); for field in typ.fields.values() { stack.extend(field.args.values().map(|arg| arg.type_of.clone())); @@ -851,4 +855,30 @@ mod tests { )]); assert_eq!(actual, expected); } + + #[test] + fn test_unused_types_with_cyclic_types() { + let config = Config::from_sdl( + " + type Bar {a: Int} + type Foo {a: [Foo]} + + type Query { + foos: [Foo] + } + + schema { + query: Query + } + ", + ) + .to_result() + .unwrap(); + + let actual = config.unused_types(); + let mut expected = HashSet::new(); + expected.insert("Bar".to_string()); + + assert_eq!(actual, expected); + } }