Skip to content
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

Cannot read property 'multipliers' of undefined #15

Closed
blacksmoke26 opened this issue Feb 9, 2019 · 5 comments · May be fixed by saurabharch/type-graphql#3
Closed

Cannot read property 'multipliers' of undefined #15

blacksmoke26 opened this issue Feb 9, 2019 · 5 comments · May be fixed by saurabharch/type-graphql#3

Comments

@blacksmoke26
Copy link

blacksmoke26 commented Feb 9, 2019

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
Copy link
Collaborator

ivome commented Feb 10, 2019

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
Copy link
Collaborator

ivome commented Feb 10, 2019

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
Copy link
Author

Will do. Thanks!

@ivome
Copy link
Collaborator

ivome commented Feb 14, 2019

New version is published to NPM

@blacksmoke26
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants