From 89493e6a42b866ca665ca59165749d17bf2aba90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Fri, 17 Nov 2023 10:52:10 +0100 Subject: [PATCH] chore(compiler): add a failing test for #742 --- .../tests/validation/fragments.rs | 45 +++++++++++++++++++ .../apollo-compiler/tests/validation/mod.rs | 1 + 2 files changed, 46 insertions(+) create mode 100644 crates/apollo-compiler/tests/validation/fragments.rs diff --git a/crates/apollo-compiler/tests/validation/fragments.rs b/crates/apollo-compiler/tests/validation/fragments.rs new file mode 100644 index 000000000..a48a0065d --- /dev/null +++ b/crates/apollo-compiler/tests/validation/fragments.rs @@ -0,0 +1,45 @@ +#[test] +fn long_fragment_chains_do_not_overflow_stack() { + // Build a query that applies thousands of fragments + // Validating it would take a lot of recursion and blow the stack + let mut query = r#" + query Introspection{ + __schema { + types { + ...typeFragment1 + } + } + } + "# + .to_string(); + + let fragments: usize = 10_000; + for i in 1..fragments { + query.push_str(&format!( + " + fragment typeFragment{i} on __Type {{ + ofType {{ + ...typeFragment{} + }} + }}", + i + 1 + )); + } + query.push_str(&format!( + " + fragment typeFragment{fragments} on __Type {{ + ofType {{ + name + }} + }}" + )); + + let (schema, executable) = apollo_compiler::parse_mixed( + format!( + "type Query {{ a: Int }} + {query}" + ), + "overflow.graphql", + ); + executable.validate(&schema).unwrap(); +} diff --git a/crates/apollo-compiler/tests/validation/mod.rs b/crates/apollo-compiler/tests/validation/mod.rs index f616b5be1..7fc193223 100644 --- a/crates/apollo-compiler/tests/validation/mod.rs +++ b/crates/apollo-compiler/tests/validation/mod.rs @@ -1,3 +1,4 @@ +mod fragments; mod interface; mod object; mod operation;