From 900167d30075c278326a48ee5f2caac1ec118631 Mon Sep 17 00:00:00 2001 From: Sunli Date: Mon, 6 Jun 2022 12:08:59 +0800 Subject: [PATCH] Fixes #848 --- src/validation/visitors/complexity.rs | 33 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/validation/visitors/complexity.rs b/src/validation/visitors/complexity.rs index c21315c2..bc1766ca 100644 --- a/src/validation/visitors/complexity.rs +++ b/src/validation/visitors/complexity.rs @@ -63,18 +63,16 @@ impl<'ctx, 'a> Visitor<'ctx> for ComplexityCalculate<'ctx, 'a> { *self.complexity_stack.last_mut().unwrap() += n; } ComplexityType::Fn(f) => { - if MetaTypeName::create(&meta_field.ty).is_list() { - match f( - ctx, - self.variable_definition.unwrap(), - &field.node, - children_complex, - ) { - Ok(n) => { - *self.complexity_stack.last_mut().unwrap() += n; - } - Err(err) => ctx.report_error(vec![field.pos], err.to_string()), + match f( + ctx, + self.variable_definition.unwrap(), + &field.node, + children_complex, + ) { + Ok(n) => { + *self.complexity_stack.last_mut().unwrap() += n; } + Err(err) => ctx.report_error(vec![field.pos], err.to_string()), } } } @@ -131,6 +129,11 @@ mod tests { todo!() } + #[graphql(complexity = "5 * child_complexity")] + async fn obj2(&self) -> MyObj { + todo!() + } + #[graphql(complexity = "count * child_complexity")] #[allow(unused_variables)] async fn objs(&self, #[graphql(default_with = "5")] count: usize) -> Vec { @@ -409,5 +412,13 @@ mod tests { }"#, 20, ); + + check_complex( + r#" + query { + obj2 { a b } + }"#, + 10, + ); } }