diff --git a/build.sbt b/build.sbt index e783e0d00d..6c95d959c4 100644 --- a/build.sbt +++ b/build.sbt @@ -33,7 +33,6 @@ val zqueryVersion = "0.7.2" val zioJsonVersion = "0.7.0" val zioHttpVersion = "3.0.0-RC9" val zioOpenTelemetryVersion = "3.0.0-RC21" -val zioPreludeVersion = "1.0.0-RC27" Global / onChangedBuildSource := ReloadOnSourceChanges @@ -176,7 +175,6 @@ lazy val core = project "dev.zio" %% "zio" % zioVersion, "dev.zio" %% "zio-streams" % zioVersion, "dev.zio" %% "zio-query" % zqueryVersion, - "dev.zio" %% "zio-prelude" % zioPreludeVersion, "dev.zio" %% "zio-test" % zioVersion % Test, "dev.zio" %% "zio-test-sbt" % zioVersion % Test, "dev.zio" %% "zio-json" % zioJsonVersion % Optional, diff --git a/core/src/main/scala/caliban/relay/PaginationArgs.scala b/core/src/main/scala/caliban/relay/PaginationArgs.scala index ab69809de7..dee4a96fe2 100644 --- a/core/src/main/scala/caliban/relay/PaginationArgs.scala +++ b/core/src/main/scala/caliban/relay/PaginationArgs.scala @@ -2,7 +2,6 @@ package caliban.relay import caliban.CalibanError import zio.Exit -import zio.prelude._ object Pagination { import PaginationCount._ @@ -12,30 +11,28 @@ object Pagination { apply(args.first, args.last, args.before, args.after) def apply[C: Cursor](args: ForwardPaginationArgs[C]): Exit[CalibanError, Pagination[C]] = - (args.first match { - case None => Validation.fail("first cannot be empty") - case Some(a) => validatePositive("first", a).map(First.apply) - }) - .zipWith(args.after match { - case None => Validation.succeed(NoCursor) - case Some(x) => Validation.fromEither(Cursor[C].decode(x)).map(After.apply) - })(new Pagination[C](_, _))( - // Explicit implicits cause thanks Scala 2.12 - ZValidation.ZValidationIdentityBoth, - implicitly - ) - .toExit + toPaginationExit( + args.first match { + case None => Left("first cannot be empty") + case Some(a) => validatePositive("first", a).map(First.apply) + }, + args.after match { + case None => Right(NoCursor) + case Some(x) => Cursor[C].decode(x).map(After.apply) + } + ) def apply[C: Cursor](args: BackwardPaginationArgs[C]): Exit[CalibanError, Pagination[C]] = - (args.last match { - case None => Validation.fail("last cannot be empty") - case Some(a) => validatePositive("last", a).map(Last.apply) - }) - .zipWith(args.before match { - case None => Validation.succeed(NoCursor) - case Some(x) => Validation.fromEither(Cursor[C].decode(x)).map(Before.apply) - })(new Pagination[C](_, _))(ZValidation.ZValidationIdentityBoth, implicitly) - .toExit + toPaginationExit( + args.last match { + case None => Left("last cannot be empty") + case Some(a) => validatePositive("last", a).map(Last.apply) + }, + args.before match { + case None => Right(NoCursor) + case Some(x) => Cursor[C].decode(x).map(Before.apply) + } + ) def apply[C: Cursor]( first: Option[Int], @@ -43,30 +40,31 @@ object Pagination { before: Option[String], after: Option[String] ): Exit[CalibanError, Pagination[C]] = - validateFirstLast(first, last) - .zipWith(validateCursors(before, after))(new Pagination[C](_, _))(ZValidation.ZValidationIdentityBoth, implicitly) - .toExit + toPaginationExit( + validateFirstLast(first, last), + validateCursors(before, after) + ) private def validateCursors[C: Cursor]( before: Option[String], after: Option[String] - ): Validation[String, PaginationCursor[C]] = + ): Either[String, PaginationCursor[C]] = (before, after) match { case (Some(_), Some(_)) => - Validation.fail("before and after cannot both be set") + Left("before and after cannot both be set") case (Some(x), _) => - Validation.fromEither(Cursor[C].decode(x)).map(Before.apply) + Cursor[C].decode(x).map(Before.apply) case (_, Some(x)) => - Validation.fromEither(Cursor[C].decode(x)).map(After.apply) - case (None, None) => Validation.succeed(NoCursor) + Cursor[C].decode(x).map(After.apply) + case (None, None) => Right(NoCursor) } private def validateFirstLast(first: Option[Int], last: Option[Int]) = (first, last) match { case (None, None) => - Validation.fail("first and last cannot both be empty") + Left("first and last cannot both be empty") case (Some(_), Some(_)) => - Validation.fail("first and last cannot both be set") + Left("first and last cannot both be set") case (Some(a), _) => validatePositive("first", a).map(First.apply) case (_, Some(b)) => @@ -74,13 +72,19 @@ object Pagination { } private def validatePositive(which: String, i: Int) = - if (i > -1) Validation.succeed(i) else Validation.fail(s"$which cannot be negative") - - private implicit class ValidationOps[E, A](private val v: Validation[String, A]) extends AnyVal { - def toExit: Exit[CalibanError, A] = { - val either = v.toEitherWith(errors => CalibanError.ExecutionError(msg = errors.mkString(", "))) - Exit.fromEither(either) + if (i > -1) Right(i) else Left(s"$which cannot be negative") + + private def toPaginationExit[C]( + count: Either[String, PaginationCount], + cursor: Either[String, PaginationCursor[C]] + ): Exit[CalibanError, Pagination[C]] = { + val v = (count, cursor) match { + case (Right(c), Right(r)) => Right(new Pagination(c, r)) + case (Left(c), Left(r)) => Left(List(c, r)) + case (Left(c), _) => Left(List(c)) + case (_, Left(r)) => Left(List(r)) } + Exit.fromEither(v.left.map(errors => CalibanError.ExecutionError(msg = errors.mkString(", ")))) } } diff --git a/core/src/main/scala/caliban/validation/FragmentValidator.scala b/core/src/main/scala/caliban/validation/FragmentValidator.scala index 6f9b8aa59e..444f0caf0b 100644 --- a/core/src/main/scala/caliban/validation/FragmentValidator.scala +++ b/core/src/main/scala/caliban/validation/FragmentValidator.scala @@ -5,8 +5,6 @@ import caliban.introspection.adt._ import caliban.parsing.adt.Selection import caliban.validation.Utils._ import zio.Chunk -import zio.prelude._ -import zio.prelude.fx.ZPure import scala.collection.mutable import scala.util.hashing.MurmurHash3 @@ -64,12 +62,12 @@ object FragmentValidator { def doTypesConflict(t1: __Type, t2: __Type): Boolean = if (isNonNull(t1)) - if (isNonNull(t2)) (t1.ofType, t2.ofType).mapN((p1, p2) => doTypesConflict(p1, p2)).getOrElse(true) + if (isNonNull(t2)) t1.ofType.flatMap(p1 => t2.ofType.map(p2 => doTypesConflict(p1, p2))).getOrElse(true) else true else if (isNonNull(t2)) true else if (isListType(t1)) - if (isListType(t2)) (t1.ofType, t2.ofType).mapN((p1, p2) => doTypesConflict(p1, p2)).getOrElse(true) + if (isListType(t2)) t1.ofType.flatMap(p1 => t2.ofType.map(p2 => doTypesConflict(p1, p2))).getOrElse(true) else true else if (isListType(t2)) true diff --git a/core/src/main/scala/caliban/wrappers/Caching.scala b/core/src/main/scala/caliban/wrappers/Caching.scala index 49bd2dde0a..eb18ac62bf 100644 --- a/core/src/main/scala/caliban/wrappers/Caching.scala +++ b/core/src/main/scala/caliban/wrappers/Caching.scala @@ -9,11 +9,11 @@ import caliban.parsing.adt.{ Directive, Document } import caliban.schema.Annotations.{ GQLDirective, GQLName } import caliban.schema.Types import caliban.wrappers.Wrapper.{ EffectfulWrapper, FieldWrapper, OverallWrapper, ValidationWrapper } -import zio.prelude._ import zio.query.ZQuery -import zio.{ durationInt, Duration, Exit, FiberRef, Ref, UIO, Unsafe, ZIO } +import zio.{ duration2DurationOps, durationInt, Duration, Exit, FiberRef, Ref, UIO, Unsafe, ZIO } import java.util.concurrent.{ ConcurrentHashMap, TimeUnit } +import scala.collection.compat._ object Caching { val DirectiveName = "cacheControl" @@ -167,15 +167,13 @@ object Caching { override def toString: String = "PUBLIC" } - implicit val ord: Ord[CacheScope] = Ord.make { - case (Private, Private) => Ordering.Equals - case (Public, Public) => Ordering.Equals - case (Private, Public) => Ordering.LessThan - case (Public, Private) => Ordering.GreaterThan + implicit val ordering: Ordering[CacheScope] = { + case (Private, Private) => 0 + case (Public, Public) => 0 + case (Private, Public) => -1 + case (Public, Private) => 1 } - implicit val ordering: scala.math.Ordering[CacheScope] = ord.toScala - val _type = __Type( __TypeKind.ENUM, Some("CacheScope"),