Skip to content

Commit

Permalink
fix(config): overflow issue in get_all_used_type_names in case of cyc…
Browse files Browse the repository at this point in the history
…lic type (#2109)
  • Loading branch information
bnchi authored Jun 5, 2024
1 parent d4d04ea commit 9cdf3ef
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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);
}
}

1 comment on commit 9cdf3ef

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 6.75ms 3.06ms 79.52ms 70.98%
Req/Sec 3.75k 191.91 4.53k 90.42%

447249 requests in 30.02s, 2.24GB read

Requests/sec: 14900.53

Transfer/sec: 76.48MB

Please sign in to comment.