Cannot read property 'multipliers' of undefined
blacksmoke26 opened this issue · 5 comments
blacksmoke26 commented
Schema / Definition:
directive @complexity(
# The complexity value for the field
value: Int!,
# Optional multipliers
multipliers: [String!]
) on FIELD_DEFINITION
myProperties ( limit: Int!, findOptions: JSON ):
PropertiesConnection @auth @complexity(value: 5, multipliers:["limit"])
...
Added to validationRules: (ApolloServer 2
)
validationRules: [ queryComplexity.default({
estimators: [
directiveEstimator({
name: 'complexity',
}),
],
maximumComplexity: 1000,
variables: req.body.variables || {},
// Optional function to create a custom error
createError: (max, actual) => {
return new GraphQLError(`Query is too complex: ${actual}. Maximum allowed complexity: ${max}`);
},
onComplete: (complexity) => {console.log('Query Complexity:', complexity);},
})]
the Query:
myProperties (
limit: 5
) {
nodes {
title
}
}
and above code throws the following error:
{
"statusCode": 500,
"error": "Internal Server Error",
"message": "Cannot read property 'multipliers' of undefined"
}
any clue, what am doing wrong? BTW simpleEstimator
works fine.
ivome commented
Looks like variables
is undefined. Did you check if the value of req.body.variables
in your code?
There is also some discussion under #7 regarding this (maybe also check the related discussions under the Apollo Server issues and pull requests...)
ivome commented
I am pretty confident I fixed the issue with the latest commit. Could you check on your end if that solved it? Then I'll push a new release to NPM
blacksmoke26 commented
Will do. Thanks!
ivome commented
New version is published to NPM
blacksmoke26 commented
Thank you!