-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Exponential complexity calculation #44
Comments
This sounds like a good thing to add to the directive estimator. With the We would just have to decide how this behaves with the multipliers (that are meant for this exact feature). Maybe we call this Something like this: type Query {
posts(limit: Int): [Post] @complexity(multipliers: ["limit"], defaultMultiplier: 50)
} If no limit is provided, the default multiplier of 50 is used, otherwise, the limit is used as the multiplier. Would that work for your use-case? |
Yes this would be a possibility. But it is quite verbose when typing The field level multipliers mostly have effect on the root level query (e.g. How about alternatively passing an int to the multipliers prop?
|
How do you want to define the input types for that argument? This needs to be strictly typed in GraphQL. |
Right, this is not possible. I was just in the typescript thinking How about a specific complexity multiplier directive that can be configured centrally? Then the original concept of the simple directive estimator is unchanged. The new directive would solely focus on the exponential complexity. Both directives could be used for estimating complexity if needed The idea of the existing Directive estimator is more focused on linear growth of the fetched data in my opinion How about this:
|
This would definitely work and could be implemented with a custom estimator. Only issue with that would be if you have input values that need to change the factor: {
posts(limit: 1000000) {
title
}
} Then you probably end up with a solution like I suggested above. But you could certainly configure two estimators with different directives that have different behaviors. |
This should be possible by combining the annotations and using both estimators:
We on our side would solely rely on the exponential estimator with small multipliers (e.g. 3), but the combination of both estimators should still be possible. |
So I think we have these options discussed:
Both are fine I think. Which would you prefer? |
I think the |
Is there any update on this feature? Would be super nice! |
I haven't found the time to look into that. Happy to review and merge a PR if anyone wants to add this. |
Curious about this too. I am interested in ensuring certain fields are only selectable in top level, i.e. controlling the depth. For example: query UserWithFriends {
id
name
username
friends { # this should be allowed
id
name
username
friends { # this should not be allowed
id
name
username
friends {
# matrix...
}
}
}
} |
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:
This also could be extended on the options for the directive estimator:
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:
With the queries
All queries have a simple complexity of around 5. Using the directive Estimator q2 has a complexity of
22
and q321
, although the amount of returned entities is exponentially bigger in q3.The text was updated successfully, but these errors were encountered: