-
Notifications
You must be signed in to change notification settings - Fork 41
feat/connectcost: Add support for connections in complexity calculation #762
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
base: main
Are you sure you want to change the base?
Conversation
|
9884894
to
4dc6831
Compare
4dc6831
to
8c0bd56
Compare
return arg.value.kind === 'IntValue' ? parseInt(arg.value.value, 10) : 1; | ||
} | ||
return mult; | ||
}, 1) : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution :)
This function is already fairly complex, and it would be preferred that we avoid using a reduce in favor of more readable items:
let multiplier = 1
if ('arguments' in node && node.arguments) {
if (arg.name.value === 'first' || arg.name.value === 'last') {
multiplier = arg.value.kind === 'IntValue' ? parseInt(arg.value.value, 10) : multiplier
}
}
Also, we should check that parseInt does not return NaN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice if this could be configurable, like supporting a limit
argument as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The cost-multiplier logic based on first/last arguments is a solid feature, but it’s hidden as an implementation detail. It also frames this as a Relay specific addition, which probably isn't the main goal (I use relay spec, so I'm not complaining about that!).
To improve clarity and flexibility as mentioned by @marceloverdijk, could we expose it as a config option? Naming ideas below:
costMultiplyingArgs: string[] | false; // or empty array if don't want to deal with false
// or
costMultiplyingPaginationArgs: string[] | false;
// the default could be ['first', 'last'] if needed for backwards compat
This would:
- Make the behavior visible in the public API (even if users don't deviate from default, at least it's clear there is a cost multiplier for pagination args)
- Let users extend it to support
limit
,take
, etc. - Let users disable it entirely (setting to false or empty array)
Right now, users might miss that this logic is in effect, or be unable to adapt it to different pagination conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello !
Thanks a lot for your contribution. I added some comments above to improve the PR before we can merge it :)
I think this PR could be closed as it was merged and released here? |
The cost complexity cost-limit plugin does not take into account how many entities are being returned when either the first or last argument are specified at the field level. This PR supports calculating complexity based on the number of records requested in the query.
This commit fixes #761
These two examples which have the same complexity cost (I have omitted edges and pageInfo to keep these examples simple)
The cost complexity of the query below should increase by a factor of the number of books requested
Note the PR does not currently handle VariableDefinitions but will handle the example above