From 42694dced6b11457688773455b77e6328a7051e8 Mon Sep 17 00:00:00 2001 From: Yann Simon Date: Mon, 14 Aug 2023 11:42:27 +0200 Subject: [PATCH] remove errors limit on construtor --- ...verlappingFieldsCanBeMergedBenchmark.scala | 4 +-- .../execution/QueryReducerExecutor.scala | 5 ++-- .../execution/batch/BatchExecutor.scala | 5 ++-- .../ResolverBasedAstSchemaBuilder.scala | 5 ++-- .../sangria/validation/QueryValidator.scala | 28 +++++-------------- 5 files changed, 18 insertions(+), 29 deletions(-) diff --git a/modules/benchmarks/src/main/scala/sangria/benchmarks/OverlappingFieldsCanBeMergedBenchmark.scala b/modules/benchmarks/src/main/scala/sangria/benchmarks/OverlappingFieldsCanBeMergedBenchmark.scala index 07b0b558..f0169695 100644 --- a/modules/benchmarks/src/main/scala/sangria/benchmarks/OverlappingFieldsCanBeMergedBenchmark.scala +++ b/modules/benchmarks/src/main/scala/sangria/benchmarks/OverlappingFieldsCanBeMergedBenchmark.scala @@ -11,7 +11,7 @@ import sangria.validation.{QueryValidator, RuleBasedQueryValidator, Violation} @State(Scope.Thread) class OverlappingFieldsCanBeMergedBenchmark { - val validator: QueryValidator = RuleBasedQueryValidator( + val validator: QueryValidator = new RuleBasedQueryValidator( List(new rules.OverlappingFieldsCanBeMerged)) val schema: Schema[_, _] = @@ -98,7 +98,7 @@ class OverlappingFieldsCanBeMergedBenchmark { bh.consume(doValidate(validator, deepAbstractConcrete)) private def doValidate(validator: QueryValidator, document: Document): Vector[Violation] = { - val result = validator.validateQuery(schema, document) + val result = validator.validateQuery(schema, document, None) require(result.isEmpty) result } diff --git a/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala b/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala index c086c064..d82ccefa 100644 --- a/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala +++ b/modules/core/src/main/scala/sangria/execution/QueryReducerExecutor.scala @@ -19,9 +19,10 @@ object QueryReducerExecutor { queryValidator: QueryValidator = QueryValidator.default, exceptionHandler: ExceptionHandler = ExceptionHandler.empty, deprecationTracker: DeprecationTracker = DeprecationTracker.empty, - middleware: List[Middleware[Ctx]] = Nil + middleware: List[Middleware[Ctx]] = Nil, + errorsLimit: Option[Int] = None )(implicit executionContext: ExecutionContext): Future[(Ctx, TimeMeasurement)] = { - val violations = queryValidator.validateQuery(schema, queryAst) + val violations = queryValidator.validateQuery(schema, queryAst, errorsLimit) if (violations.nonEmpty) Future.failed(ValidationError(violations, exceptionHandler)) diff --git a/modules/core/src/main/scala/sangria/execution/batch/BatchExecutor.scala b/modules/core/src/main/scala/sangria/execution/batch/BatchExecutor.scala index f59d49cd..17de05f9 100644 --- a/modules/core/src/main/scala/sangria/execution/batch/BatchExecutor.scala +++ b/modules/core/src/main/scala/sangria/execution/batch/BatchExecutor.scala @@ -75,7 +75,8 @@ object BatchExecutor { middleware: List[Middleware[Ctx]] = Nil, maxQueryDepth: Option[Int] = None, queryReducers: List[QueryReducer[Ctx, _]] = Nil, - inferVariableDefinitions: Boolean = true + inferVariableDefinitions: Boolean = true, + errorsLimit: Option[Int] = None )(implicit executionContext: ExecutionContext, marshaller: SymmetricMarshaller[T], @@ -100,7 +101,7 @@ object BatchExecutor { inferVariableDefinitions, exceptionHandler)) .flatMap { case res @ (updatedDocument, _) => - val violations = queryValidator.validateQuery(schema, updatedDocument) + val violations = queryValidator.validateQuery(schema, updatedDocument, errorsLimit) if (violations.nonEmpty) Failure(ValidationError(violations, exceptionHandler)) else Success(res) diff --git a/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala b/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala index d738f362..7d711e68 100644 --- a/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala +++ b/modules/core/src/main/scala/sangria/schema/ResolverBasedAstSchemaBuilder.scala @@ -61,8 +61,9 @@ class ResolverBasedAstSchemaBuilder[Ctx](val resolvers: Seq[AstSchemaResolver[Ct def validateSchema( schema: ast.Document, - validator: QueryValidator = ResolverBasedAstSchemaBuilder.validator): Vector[Violation] = - allowKnownDynamicDirectives(validator.validateQuery(validationSchema, schema)) + validator: QueryValidator = ResolverBasedAstSchemaBuilder.validator, + errorsLimit: Option[Int] = None): Vector[Violation] = + allowKnownDynamicDirectives(validator.validateQuery(validationSchema, schema, errorsLimit)) def validateSchemaWithException( schema: ast.Document, diff --git a/modules/core/src/main/scala/sangria/validation/QueryValidator.scala b/modules/core/src/main/scala/sangria/validation/QueryValidator.scala index ebffd0d2..5127029c 100644 --- a/modules/core/src/main/scala/sangria/validation/QueryValidator.scala +++ b/modules/core/src/main/scala/sangria/validation/QueryValidator.scala @@ -11,7 +11,7 @@ import scala.collection.mutable.{ListBuffer, Map => MutableMap, Set => MutableSe import scala.reflect.{ClassTag, classTag} trait QueryValidator { - def validateQuery(schema: Schema[_, _], queryAst: ast.Document): Vector[Violation] +// def validateQuery(schema: Schema[_, _], queryAst: ast.Document): Vector[Violation] def validateQuery( schema: Schema[_, _], queryAst: ast.Document, @@ -49,41 +49,32 @@ object QueryValidator { new SingleFieldSubscriptions ) - @deprecated("use ruleBased setting 'errorsLimit' instead", "4.0.1") def ruleBased(rules: List[ValidationRule]): RuleBasedQueryValidator = - RuleBasedQueryValidator(rules) - def ruleBased(rules: List[ValidationRule], errorsLimit: Option[Int]): RuleBasedQueryValidator = - new RuleBasedQueryValidator(rules, errorsLimit) + new RuleBasedQueryValidator(rules) val empty: QueryValidator = new QueryValidator { - def validateQuery(schema: Schema[_, _], queryAst: ast.Document): Vector[Violation] = - Vector.empty def validateQuery( schema: Schema[_, _], queryAst: ast.Document, errorsLimit: Option[Int]): Vector[Violation] = Vector.empty } - val default: RuleBasedQueryValidator = ruleBased(allRules, errorsLimit = Some(10)) + val default: RuleBasedQueryValidator = ruleBased(allRules) } class RuleBasedQueryValidator( - rules: List[ValidationRule], - errorsLimit: Option[Int] + rules: List[ValidationRule] ) extends QueryValidator { - def validateQuery(schema: Schema[_, _], queryAst: ast.Document): Vector[Violation] = - validateQuery(schema, queryAst, errorsLimit) - def validateQuery( schema: Schema[_, _], queryAst: ast.Document, - errorsLimitOverride: Option[Int]): Vector[Violation] = { + errorsLimit: Option[Int]): Vector[Violation] = { val ctx = new ValidationContext( schema, queryAst, queryAst.sourceMapper, new TypeInfo(schema), - errorsLimitOverride) + errorsLimit) validateUsingRules(queryAst, ctx, rules.map(_.visitor(ctx)), topLevel = true) @@ -166,15 +157,10 @@ class RuleBasedQueryValidator( val cls = classTag[T].runtimeClass val newRules = rules.filterNot(r => cls.isAssignableFrom(r.getClass)) - RuleBasedQueryValidator(newRules) + new RuleBasedQueryValidator(newRules) } } -object RuleBasedQueryValidator { - def apply(rules: List[ValidationRule]): RuleBasedQueryValidator = - new RuleBasedQueryValidator(rules, None) -} - class ValidationContext( val schema: Schema[_, _], val doc: ast.Document,