Skip to content

Cannot read property 'multipliers' of undefined #15

Closed
saurabharch/type-graphql
#3
@blacksmoke26

Description

@blacksmoke26

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions