Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add fallback for missing child complexity in simple estimator #58

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

Closed
kjarmicki wants to merge 1 commit into slicknode:master from kjarmicki:master

Conversation

Copy link

@kjarmicki kjarmicki commented Sep 6, 2021

Hello,

In the docs it states that the simple estimator "can be used as the last estimator in the chain for a default value". Unfortunately, that's not always the case - if child node complexity computation fails, then args.childComplexity will be NaN, resulting in NaN value for the entire complexity estimation and an error being passed to the context here:

if (!validScore) {
return this.context.reportError(
new GraphQLError(
`No complexity could be calculated for field ${typeDef.name}.${field.name}. ` +
'At least one complexity estimator has to return a complexity score.'
)
);
}

This PR fixes that by assuming NaN value of child complexity calculation to be equal to 0 and falling back to the default complexity value.

Copy link
Collaborator

ivome commented Sep 7, 2021

Hi @kjarmicki, thanks for the PR! I am not sure if it's a good idea to suppress that error. This library assumes that a valid GraphQL query is passed with valid variable values. There are a lot of other cases where an error in the GraphQL query / variable values leads to unintended behavior. I don't think we should hide and suppress those errors. As a user of the simpleEstimator I would never expect that an invalid scalar in some deeply nested query essentially disables the query complexity calculation for that part of the query tree instead of raising an error.

If you are doing a standalone calculation of the query complexity, it's probably best to validate the query first using the validation methods from graphql-js.

Copy link
Author

Oh, ok. Sounds reasonable, thank you for the explanation 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /