Skip to content

Commit

Permalink
test: unintentional recursion panic (#890)
Browse files Browse the repository at this point in the history
There was a report in #838 that the panic I added to detect recursive
queries that hadn't been marked as `#[cynic(recurse = N)]` wasn't
working. This PR adds some tests of that.
  • Loading branch information
obmarg authored Apr 6, 2024
1 parent 21cec74 commit fea5462
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions cynic/tests/recursive-queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,50 @@ mod recursing_through_inline_fragments {
"###);
}
}

mod recursing_without_recursse {
use cynic_proc_macros::InlineFragments;

#[test]
#[should_panic(
expected = "Maximum query depth exceeded. Have you forgotten to mark a query as recursive?"
)]
fn test_recursion_without_recurse_panics_correctly() {
// This example _should_ hit a panic I've added rather than just overflowing
// the stack. This test makes sure it does.
use super::*;

#[derive(QueryFragment, Serialize)]
#[cynic(graphql_type = "Query", schema_path = "tests/test-schema.graphql")]
struct AllDataQuery {
all_data: Vec<PostOrAuthor>,
}

#[derive(InlineFragments, Serialize)]
#[cynic(schema_path = "tests/test-schema.graphql")]
enum PostOrAuthor {
Author(Author),
Post(Post),
#[cynic(fallback)]
Other,
}

#[derive(QueryFragment, Serialize)]
#[cynic(graphql_type = "BlogPost", schema_path = "tests/test-schema.graphql")]
struct Post {
__typename: String,
}

#[derive(QueryFragment, Serialize)]
#[cynic(schema_path = "tests/test-schema.graphql")]
struct Author {
// #[cynic(recurse = "2")]
#[cynic(flatten)]
friends: Vec<Author>,
}

use cynic::QueryBuilder;

AllDataQuery::build(());
}
}

0 comments on commit fea5462

Please sign in to comment.