Fixes #848
This commit is contained in:
parent
144c773cd7
commit
900167d300
|
@ -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<MyObj> {
|
||||
|
@ -409,5 +412,13 @@ mod tests {
|
|||
}"#,
|
||||
20,
|
||||
);
|
||||
|
||||
check_complex(
|
||||
r#"
|
||||
query {
|
||||
obj2 { a b }
|
||||
}"#,
|
||||
10,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue