Description
There should be a possibility for an exponential complexity calculation. Our graphql data models have a lot of relations and most of these can return multiple entities. Therefore the depth of the query can exponentially increase the returned data size. This should be possible to be taken into account in the complexity calculation.
The complexity of a type which is fetched as part of a set should exponentially increase the complexity. This could be extended for the DirectiveEstimator:
type board {
posts: [Post] @Complexity(childMultiplier: 3) #complexity.value should be optional
}
This also could be extended on the options for the directive estimator:
directiveEstimator({ childComplexity: 1, childListMultiplier: 3 })
The childListMultiplier calculates the complexity of the child sub query and multiplies it with the defined value
Example
The following example shows the issue without exponential complexity calculation:
type Board { name: String
posts: [Post] @Complexity(value: 5)
}
type User { name: String
boards: [Board] @Complexity(value: 5)
}
type Post { text: String
viewers: [User] @Complexity(value: 5)
}
type Query {
boards(ids: [ID]): [Board] @Complexity(value: 5)
}
With the queries
query {
q1: boards(ids:["1"]) { n1: name n2: name n3: name n4: name }
q2: boards(ids:["1"] { posts { text } posts2: posts { viewers { name } } }
q3: boards(ids:["1"] { posts { viewers { boards { name } } } }
}
All queries have a simple complexity of around 5. Using the directive Estimator q2 has a complexity of 22
and q3 21
, although the amount of returned entities is exponentially bigger in q3.