From fe6a76e36eea4371944a5b26cefd9fefe7aed46c Mon Sep 17 00:00:00 2001 From: kyri-petrou <67301607+kyri-petrou@users.noreply.github.com> Date: Tue, 28 May 2024 03:17:26 +0200 Subject: [PATCH] Cleanup usages of Configurator (#2250) --- .../scala/caliban/QuickRequestHandler.scala | 2 +- .../main/scala/caliban/quick/package.scala | 2 +- .../execution/NestedZQueryBenchmark.scala | 60 +++++++++---------- .../src/main/scala/caliban/Configurator.scala | 35 ++++------- core/src/main/scala/caliban/GraphQL.scala | 44 +++++++------- .../scala/caliban/HttpRequestMethod.scala | 8 ++- .../scala/caliban/validation/Validator.scala | 3 +- .../wrappers/ApolloPersistedQueries.scala | 2 +- .../caliban/wrappers/CostEstimation.scala | 4 +- .../scala/caliban/wrappers/Wrappers.scala | 4 +- .../scala/caliban/wrappers/WrappersSpec.scala | 2 +- 11 files changed, 77 insertions(+), 89 deletions(-) diff --git a/adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala b/adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala index eafd1dd44..8426b1a01 100644 --- a/adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala +++ b/adapters/quick/src/main/scala/caliban/QuickRequestHandler.scala @@ -26,7 +26,7 @@ final private class QuickRequestHandler[R]( def configure(config: ExecutionConfiguration)(implicit trace: Trace): QuickRequestHandler[R] = new QuickRequestHandler[R]( - interpreter.wrapExecutionWith[R, Any](Configurator.setWith(config)(_)), + interpreter.wrapExecutionWith[R, Any](Configurator.ref.locally(config)(_)), wsConfig ) diff --git a/adapters/quick/src/main/scala/caliban/quick/package.scala b/adapters/quick/src/main/scala/caliban/quick/package.scala index 5b18b225f..87e1b6156 100644 --- a/adapters/quick/src/main/scala/caliban/quick/package.scala +++ b/adapters/quick/src/main/scala/caliban/quick/package.scala @@ -152,7 +152,7 @@ package object quick { val run: RIO[R, Nothing] = QuickAdapter(interpreter) .runServer(port, apiPath, graphiqlPath, uploadPath) - .provideSomeLayer[R](ZLayer.scoped[Any](Configurator.set(executionConfig))) + .provideSomeLayer[R](ZLayer.scoped[Any](Configurator.ref.locallyScoped(executionConfig))) ZIOApp.fromZIO(run.asInstanceOf[RIO[Any, Nothing]]).main(Array.empty) } diff --git a/benchmarks/src/main/scala/caliban/execution/NestedZQueryBenchmark.scala b/benchmarks/src/main/scala/caliban/execution/NestedZQueryBenchmark.scala index 796a161f4..c9afcf4c4 100644 --- a/benchmarks/src/main/scala/caliban/execution/NestedZQueryBenchmark.scala +++ b/benchmarks/src/main/scala/caliban/execution/NestedZQueryBenchmark.scala @@ -89,7 +89,7 @@ class NestedZQueryBenchmark { def simpleParallelQuery100(): Any = { val io = simple100 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(simpleQuery) run(io) } @@ -98,7 +98,7 @@ class NestedZQueryBenchmark { def simpleParallelQuery1000(): Any = { val io = simple1000 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(simpleQuery) run(io) } @@ -107,7 +107,7 @@ class NestedZQueryBenchmark { def simpleParallelQuery10000(): Any = { val io = simple10000 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(simpleQuery) run(io) } @@ -116,7 +116,7 @@ class NestedZQueryBenchmark { def simpleSequentialQuery100(): Any = { val io = simple100 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(simpleQuery) run(io) } @@ -125,7 +125,7 @@ class NestedZQueryBenchmark { def simpleSequentialQuery1000(): Any = { val io = simple1000 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(simpleQuery) run(io) } @@ -134,7 +134,7 @@ class NestedZQueryBenchmark { def simpleSequentialQuery10000(): Any = { val io = simple10000 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(simpleQuery) run(io) } @@ -143,7 +143,7 @@ class NestedZQueryBenchmark { def simpleBatchedQuery100(): Any = { val io = simple100 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(simpleQuery) run(io) } @@ -152,7 +152,7 @@ class NestedZQueryBenchmark { def simpleBatchedQuery1000(): Any = { val io = simple1000 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(simpleQuery) run(io) } @@ -161,7 +161,7 @@ class NestedZQueryBenchmark { def simpleBatchedQuery10000(): Any = { val io = simple10000 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(simpleQuery) run(io) } @@ -169,7 +169,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldParallelQuery100(): Any = { val io = multifield100 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(multifieldQuery) run(io) } @@ -177,7 +177,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldParallelQuery1000(): Any = { val io = multifield1000 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(multifieldQuery) run(io) } @@ -185,7 +185,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldParallelQuery10000(): Any = { val io = multifield10000 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(multifieldQuery) run(io) } @@ -193,7 +193,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldSequentialQuery100(): Any = { val io = multifield100 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(multifieldQuery) run(io) } @@ -201,7 +201,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldSequentialQuery1000(): Any = { val io = multifield1000 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(multifieldQuery) run(io) } @@ -209,7 +209,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldSequentialQuery10000(): Any = { val io = multifield10000 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(multifieldQuery) run(io) } @@ -217,7 +217,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldBatchedQuery100(): Any = { val io = multifield100 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(multifieldQuery) run(io) } @@ -225,7 +225,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldBatchedQuery1000(): Any = { val io = multifield1000 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(multifieldQuery) run(io) } @@ -233,7 +233,7 @@ class NestedZQueryBenchmark { @Benchmark def multifieldBatchedQuery10000(): Any = { val io = multifield10000 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(multifieldQuery) run(io) } @@ -241,7 +241,7 @@ class NestedZQueryBenchmark { @Benchmark def deepParallelQuery100(): Any = { val io = deep100 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(deepQuery) run(io) } @@ -249,7 +249,7 @@ class NestedZQueryBenchmark { @Benchmark def deepParallelQuery1000(): Any = { val io = deep1000 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(deepQuery) run(io) } @@ -258,7 +258,7 @@ class NestedZQueryBenchmark { def deepParallelQuery10000(): Any = { val io = deep10000 - .wrapExecutionWith(Configurator.setWith(parallel)(_)) + .wrapExecutionWith(Configurator.ref.locally(parallel)(_)) .execute(deepQuery) run(io) } @@ -267,7 +267,7 @@ class NestedZQueryBenchmark { def deepSequentialQuery100(): Any = { val io = deep100 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(deepQuery) run(io) } @@ -276,7 +276,7 @@ class NestedZQueryBenchmark { def deepSequentialQuery1000(): Any = { val io = deep1000 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(deepQuery) run(io) } @@ -285,7 +285,7 @@ class NestedZQueryBenchmark { def deepSequentialQuery10000(): Any = { val io = deep10000 - .wrapExecutionWith(Configurator.setWith(sequential)(_)) + .wrapExecutionWith(Configurator.ref.locally(sequential)(_)) .execute(deepQuery) run(io) } @@ -293,7 +293,7 @@ class NestedZQueryBenchmark { @Benchmark def deepBatchedQuery100(): Any = { val io = deep100 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(deepQuery) run(io) } @@ -301,7 +301,7 @@ class NestedZQueryBenchmark { @Benchmark def deepBatchedQuery1000(): Any = { val io = deep1000 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(deepQuery) run(io) } @@ -309,7 +309,7 @@ class NestedZQueryBenchmark { @Benchmark def deepBatchedQuery10000(): Any = { val io = deep10000 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(deepQuery) run(io) } @@ -317,7 +317,7 @@ class NestedZQueryBenchmark { @Benchmark def noWrappersBenchmark(): Any = { val io = multifield1000 - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(multifieldQuery) run(io) } @@ -325,7 +325,7 @@ class NestedZQueryBenchmark { @Benchmark def apolloTracingBenchmark(): Any = { val io = apolloInterpreter - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(multifieldQuery) run(io) } @@ -333,7 +333,7 @@ class NestedZQueryBenchmark { @Benchmark def metricsBenchmark(): Any = { val io = metricsInterpreter - .wrapExecutionWith(Configurator.setWith(batched)(_)) + .wrapExecutionWith(Configurator.ref.locally(batched)(_)) .execute(multifieldQuery) run(io) } diff --git a/core/src/main/scala/caliban/Configurator.scala b/core/src/main/scala/caliban/Configurator.scala index 9936cb7e8..941b87359 100644 --- a/core/src/main/scala/caliban/Configurator.scala +++ b/core/src/main/scala/caliban/Configurator.scala @@ -32,63 +32,48 @@ object Configurator { /** * Creates a ZLayer that can be used to set this configuration at the application level */ - def toLayer: ULayer[Unit] = ZLayer.scoped(set(self)) + def toLayer: ULayer[Unit] = ZLayer.scoped(ref.locallyScoped(self)) } - private val configRef: FiberRef[ExecutionConfiguration] = + private[caliban] val ref: FiberRef[ExecutionConfiguration] = Unsafe.unsafe(implicit u => FiberRef.unsafe.make(ExecutionConfiguration())) - private[caliban] val configuration: UIO[ExecutionConfiguration] = - configRef.get - - private[caliban] def locallyWith[R, E, A]( - cfg: ExecutionConfiguration => ExecutionConfiguration - )( - f: ZIO[R, E, A] - ): ZIO[R, E, A] = - configRef.locallyWith(cfg)(f) - - private[caliban] def set(cfg: ExecutionConfiguration): URIO[Scope, Unit] = - configRef.locallyScoped(cfg) - - private[caliban] def setWith[R, E, A](cfg: ExecutionConfiguration)(f: ZIO[R, E, A])(implicit - trace: Trace - ): ZIO[R, E, A] = - configRef.locally(cfg)(f) + private[caliban] val skipValidation: UIO[Boolean] = + ref.getWith(cfg => ZIO.succeed(cfg.skipValidation)) /** * Skip validation of the query. * @param skip if true, the query will not be validated (in that case, the `validations` field is ignored). */ def setSkipValidation(skip: Boolean): URIO[Scope, Unit] = - configRef.locallyScopedWith(_.copy(skipValidation = skip)) + ref.locallyScopedWith(_.copy(skipValidation = skip)) /** * Set the validations to run on the query during the validation phase. * @param validations the validations to run on the query during the validation phase. */ def setValidations(validations: List[QueryValidation]): URIO[Scope, Unit] = - configRef.locallyScopedWith(_.copy(validations = validations)) + ref.locallyScopedWith(_.copy(validations = validations)) /** * Enable or disable introspection queries. * @param enable if true, introspection queries are allowed. */ def setEnableIntrospection(enable: Boolean): URIO[Scope, Unit] = - configRef.locallyScopedWith(_.copy(enableIntrospection = enable)) + ref.locallyScopedWith(_.copy(enableIntrospection = enable)) /** * Set the execution strategy to use (sequential, parallel, batched). * @param queryExecution the execution strategy to use. */ def setQueryExecution(queryExecution: QueryExecution): URIO[Scope, Unit] = - configRef.locallyScopedWith(_.copy(queryExecution = queryExecution)) + ref.locallyScopedWith(_.copy(queryExecution = queryExecution)) /** * Enable or disable mutations for GET requests. See [[ExecutionConfiguration]] for more details */ def setAllowMutationsOverGetRequests(allow: Boolean): URIO[Scope, Unit] = - configRef.locallyScopedWith(_.copy(allowMutationsOverGetRequests = allow)) + ref.locallyScopedWith(_.copy(allowMutationsOverGetRequests = allow)) /** * Sets an effect which will be used to create a new ZQuery [[zio.query.Cache]] for each query execution. @@ -97,5 +82,5 @@ object Configurator { * @see [[ExecutionConfiguration]] for more details */ def setQueryCache(mkCache: UIO[Cache]): URIO[Scope, Unit] = - configRef.locallyScopedWith(_.copy(queryCache = mkCache)) + ref.locallyScopedWith(_.copy(queryCache = mkCache)) } diff --git a/core/src/main/scala/caliban/GraphQL.scala b/core/src/main/scala/caliban/GraphQL.scala index 68ee27617..be663847d 100644 --- a/core/src/main/scala/caliban/GraphQL.scala +++ b/core/src/main/scala/caliban/GraphQL.scala @@ -124,43 +124,45 @@ trait GraphQL[-R] { self => private def coerceVariables(doc: Document, variables: Map[String, InputValue])(implicit trace: Trace ): IO[ValidationError, Map[String, InputValue]] = - Configurator.configuration.flatMap { config => + Configurator.ref.getWith { config => if (doc.isIntrospection && !config.enableIntrospection) ZIO.fail(CalibanError.ValidationError("Introspection is disabled", "")) else - VariablesCoercer - .coerceVariablesEither(variables, doc, typeToValidate(doc), config.skipValidation) - .fold(ZIO.fail(_), ZIO.succeed(_)) + VariablesCoercer.coerceVariablesEither(variables, doc, typeToValidate(doc), config.skipValidation) match { + case Right(value) => ZIO.succeed(value) + case Left(error) => ZIO.fail(error) + } } private def validation( operationName: Option[String], coercedVars: Map[String, InputValue] )(doc: Document)(implicit trace: Trace): IO[ValidationError, ExecutionRequest] = - Configurator.configuration.flatMap { config => - Validator - .prepareEither( - doc, - typeToValidate(doc), - schemaToExecute(doc), - operationName, - coercedVars, - config.skipValidation, - config.validations - ) - .fold(ZIO.fail(_), checkHttpMethod(config)) + Configurator.ref.getWith { config => + Validator.prepareEither( + doc, + typeToValidate(doc), + schemaToExecute(doc), + operationName, + coercedVars, + config.skipValidation, + config.validations + ) match { + case Right(value) => checkHttpMethod(config)(value) + case Left(error) => ZIO.fail(error) + } } - private def execution( - schemaToExecute: RootSchema[R], - fieldWrappers: List[FieldWrapper[R]] + private def execution[R1 <: R]( + schemaToExecute: RootSchema[R1], + fieldWrappers: List[FieldWrapper[R1]] )(request: ExecutionRequest)(implicit trace: Trace) = { val op = request.operationType match { case OperationType.Query => schemaToExecute.query case OperationType.Mutation => schemaToExecute.mutation.getOrElse(schemaToExecute.query) case OperationType.Subscription => schemaToExecute.subscription.getOrElse(schemaToExecute.query) } - Configurator.configuration.flatMap { config => + Configurator.ref.getWith { config => Executor.executeRequest( request, op.plan, @@ -183,7 +185,7 @@ trait GraphQL[-R] { self => trace: Trace ): IO[ValidationError, ExecutionRequest] = if ((req.operationType eq OperationType.Mutation) && !cfg.allowMutationsOverGetRequests) - HttpRequestMethod.get.flatMap { + HttpRequestMethod.getWith { case HttpRequestMethod.GET => ZIO.fail(HttpRequestMethod.MutationOverGetError) case _ => ZIO.succeed(req) } diff --git a/core/src/main/scala/caliban/HttpRequestMethod.scala b/core/src/main/scala/caliban/HttpRequestMethod.scala index a81b5fad6..72ad54f40 100644 --- a/core/src/main/scala/caliban/HttpRequestMethod.scala +++ b/core/src/main/scala/caliban/HttpRequestMethod.scala @@ -1,7 +1,8 @@ package caliban import caliban.CalibanError.ValidationError -import zio.{ FiberRef, Scope, UIO, URIO, Unsafe, ZIO } +import zio.stacktracer.TracingImplicits.disableAutoTrace +import zio.{ FiberRef, Trace, Unsafe, ZIO } private[caliban] sealed trait HttpRequestMethod @@ -13,9 +14,10 @@ private[caliban] object HttpRequestMethod { private val fiberRef: FiberRef[HttpRequestMethod] = Unsafe.unsafe(implicit u => FiberRef.unsafe.make(POST)) - val get: UIO[HttpRequestMethod] = fiberRef.get + def getWith[R, E, A](zio: HttpRequestMethod => ZIO[R, E, A])(implicit trace: Trace): ZIO[R, E, A] = + fiberRef.getWith(zio) - def setWith[R, E, B](method: HttpRequestMethod)(zio: ZIO[R, E, B]): ZIO[R, E, B] = + def setWith[R, E, B](method: HttpRequestMethod)(zio: ZIO[R, E, B])(implicit trace: Trace): ZIO[R, E, B] = method match { case POST => zio case GET => fiberRef.locally(method)(zio) diff --git a/core/src/main/scala/caliban/validation/Validator.scala b/core/src/main/scala/caliban/validation/Validator.scala index c19f82edb..8b6e2e29a 100644 --- a/core/src/main/scala/caliban/validation/Validator.scala +++ b/core/src/main/scala/caliban/validation/Validator.scala @@ -52,8 +52,7 @@ object Validator { * Verifies that the given document is valid for this type. Fails with a [[caliban.CalibanError.ValidationError]] otherwise. */ def validate(document: Document, rootType: RootType)(implicit trace: Trace): IO[ValidationError, Unit] = - Configurator.configuration - .flatMap(v => ZIO.fromEither(check(document, rootType, Map.empty, v.validations).map(_ => ()))) + Configurator.ref.getWith(v => ZIO.fromEither(check(document, rootType, Map.empty, v.validations).map(_ => ()))) /** * Verifies that the given schema is valid. Fails with a [[caliban.CalibanError.ValidationError]] otherwise. diff --git a/core/src/main/scala/caliban/wrappers/ApolloPersistedQueries.scala b/core/src/main/scala/caliban/wrappers/ApolloPersistedQueries.scala index 6661ebac9..fef3de094 100644 --- a/core/src/main/scala/caliban/wrappers/ApolloPersistedQueries.scala +++ b/core/src/main/scala/caliban/wrappers/ApolloPersistedQueries.scala @@ -62,7 +62,7 @@ object ApolloPersistedQueries { ): Document => ZIO[R1, ValidationError, ExecutionRequest] = (doc: Document) => docVar.await.flatMap { - case Some((_, Some(_))) => Configurator.locallyWith(_.copy(skipValidation = true))(f(doc)) + case Some((_, Some(_))) => Configurator.ref.locallyWith(_.copy(skipValidation = true))(f(doc)) case Some((hash, None)) => f(doc) <* ApolloPersistence.add(hash, doc) case None => f(doc) } diff --git a/core/src/main/scala/caliban/wrappers/CostEstimation.scala b/core/src/main/scala/caliban/wrappers/CostEstimation.scala index d8fb78f10..abc008a92 100644 --- a/core/src/main/scala/caliban/wrappers/CostEstimation.scala +++ b/core/src/main/scala/caliban/wrappers/CostEstimation.scala @@ -190,7 +190,7 @@ object CostEstimation { ): Document => ZIO[R1, ValidationError, ExecutionRequest] = (doc: Document) => process(doc).tap { req => - ZIO.unlessZIO(ZIO.succeed(skipForPersistedQueries) && Configurator.configuration.map(_.skipValidation)) { + ZIO.unlessZIO(ZIO.succeed(skipForPersistedQueries) && Configurator.skipValidation) { val cost = computeCost(req.field)(f) ZIO.when(cost > maxCost)(ZIO.fail(error(cost))) } @@ -213,7 +213,7 @@ object CostEstimation { ): Document => ZIO[R1, ValidationError, ExecutionRequest] = (doc: Document) => process(doc).tap { req => - ZIO.unlessZIO(ZIO.succeed(skipForPersistedQueries) && Configurator.configuration.map(_.skipValidation)) { + ZIO.unlessZIO(ZIO.succeed(skipForPersistedQueries) && Configurator.skipValidation) { computeCostZIO(req.field)(f).flatMap { cost => ZIO.when(cost > maxCost)( ZIO.fail(ValidationError(s"Query costs too much: $cost. Max cost: $maxCost.", "")) diff --git a/core/src/main/scala/caliban/wrappers/Wrappers.scala b/core/src/main/scala/caliban/wrappers/Wrappers.scala index a09fc03ec..05a259d8d 100644 --- a/core/src/main/scala/caliban/wrappers/Wrappers.scala +++ b/core/src/main/scala/caliban/wrappers/Wrappers.scala @@ -109,7 +109,7 @@ object Wrappers { ): Document => ZIO[R1, ValidationError, ExecutionRequest] = (doc: Document) => process(doc).tap { req => - ZIO.unlessZIO(Configurator.configuration.map(_.skipValidation)) { + ZIO.unlessZIO(Configurator.skipValidation) { calculateDepth(req.field).flatMap { depth => ZIO.when(depth > maxDepth)( ZIO.fail(ValidationError(s"Query is too deep: $depth. Max depth: $maxDepth.", "")) @@ -141,7 +141,7 @@ object Wrappers { ): Document => ZIO[R1, ValidationError, ExecutionRequest] = (doc: Document) => process(doc).tap { req => - ZIO.unlessZIO(Configurator.configuration.map(_.skipValidation)) { + ZIO.unlessZIO(Configurator.skipValidation) { countFields(req.field).flatMap { fields => ZIO.when(fields > maxFields)( ZIO.fail(ValidationError(s"Query has too many fields: $fields. Max fields: $maxFields.", "")) diff --git a/core/src/test/scala/caliban/wrappers/WrappersSpec.scala b/core/src/test/scala/caliban/wrappers/WrappersSpec.scala index 1e555af5b..41742f8c8 100644 --- a/core/src/test/scala/caliban/wrappers/WrappersSpec.scala +++ b/core/src/test/scala/caliban/wrappers/WrappersSpec.scala @@ -301,7 +301,7 @@ object WrappersSpec extends ZIOSpecDefault { ): Document => ZIO[R1, ValidationError, ExecutionRequest] = (doc: Document) => f(doc) <* { - ZIO.unlessZIO(Configurator.configuration.map(_.skipValidation)) { + ZIO.unlessZIO(Configurator.skipValidation) { ZIO.whenZIO(fail.get)(ZIO.fail(ValidationError("boom", "boom"))) } }