Skip to content

Commit

Permalink
chore(compiler): add a failing test for #742
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Nov 17, 2023
1 parent f1debb1 commit 89493e6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions crates/apollo-compiler/tests/validation/fragments.rs
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions crates/apollo-compiler/tests/validation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod fragments;
mod interface;
mod object;
mod operation;
Expand Down

0 comments on commit 89493e6

Please sign in to comment.