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

remove errors limit on construtor #2

Draft
wants to merge 1 commit into
base: limit-errors-july-2023
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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[_, _] =
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down