diff --git a/build.sbt b/build.sbt index 7be60c6..da59658 100644 --- a/build.sbt +++ b/build.sbt @@ -1,15 +1,15 @@ -lazy val catsEffectVersion = "1.1.0" -lazy val catsVersion = "1.5.0" -lazy val circeVersion = "0.10.0" -lazy val doobieVersion = "0.6.0" -lazy val fs2Version = "1.0.2" -lazy val kindProjectorVersion = "0.9.9" -lazy val log4catsVersion = "0.2.0" -lazy val sangriaCirceVersion = "1.2.1" +lazy val catsEffectVersion = "2.1.3" +lazy val catsVersion = "2.1.1" +lazy val circeVersion = "0.13.0" +lazy val doobieVersion = "0.9.0" +lazy val fs2Version = "2.3.0" +lazy val kindProjectorVersion = "0.9.10" +lazy val log4catsVersion = "1.0.1" +lazy val sangriaCirceVersion = "1.3.0" lazy val sangriaVersion = "1.4.2" -lazy val scala12Version = "2.12.8" -lazy val http4sVersion = "0.20.0-M4" -lazy val slf4jVersion = "1.7.25" +lazy val scala12Version = "2.12.11" +lazy val http4sVersion = "0.21.4" +lazy val slf4jVersion = "1.7.30" lazy val scalacSettings = Seq( scalacOptions ++= diff --git a/modules/core/src/main/scala/Main.scala b/modules/core/src/main/scala/Main.scala index 515e8e8..f5ead05 100644 --- a/modules/core/src/main/scala/Main.scala +++ b/modules/core/src/main/scala/Main.scala @@ -23,12 +23,13 @@ import org.http4s.implicits._ import org.http4s.server.Server import org.http4s.server.blaze._ import scala.concurrent.ExecutionContext +import scala.concurrent.ExecutionContext.global object Main extends IOApp { // Construct a transactor for connecting to the database. def transactor[F[_]: Async: ContextShift]( - bec: ExecutionContext + blocker: Blocker ): Resource[F, HikariTransactor[F]] = ExecutionContexts.fixedThreadPool[F](10).flatMap { ce => HikariTransactor.newHikariTransactor( @@ -37,7 +38,7 @@ object Main extends IOApp { "user", "password", ce, - bec + blocker ) } @@ -58,14 +59,14 @@ object Main extends IOApp { // Playground or else redirect to playground def playgroundOrElse[F[_]: Sync: ContextShift]( - blockingContext: ExecutionContext + blocker: Blocker ): HttpRoutes[F] = { object dsl extends Http4sDsl[F]; import dsl._ HttpRoutes.of[F] { case GET -> Root / "playground.html" => StaticFile - .fromResource[F]("/assets/playground.html", blockingContext) + .fromResource[F]("/assets/playground.html", blocker) .getOrElseF(NotFound()) case _ => @@ -78,7 +79,7 @@ object Main extends IOApp { def server[F[_]: ConcurrentEffect: ContextShift: Timer]( routes: HttpRoutes[F] ): Resource[F, Server[F]] = - BlazeServerBuilder[F] + BlazeServerBuilder[F](global) .bindHttp(8080, "localhost") .withHttpApp(routes.orNotFound) .resource @@ -88,16 +89,16 @@ object Main extends IOApp { implicit L: Logger[F] ): Resource[F, Server[F]] = for { - bec <- ExecutionContexts.cachedThreadPool[F] - xa <- transactor[F](bec) - gql = graphQL[F](xa, bec) - rts = GraphQLRoutes[F](gql) <+> playgroundOrElse(bec) + b <- Blocker[F] + xa <- transactor[F](b) + gql = graphQL[F](xa, b.blockingContext) + rts = GraphQLRoutes[F](gql) <+> playgroundOrElse(b) svr <- server[F](rts) } yield svr // Our entry point starts the server and blocks forever. def run(args: List[String]): IO[ExitCode] = { - implicit val log = Slf4jLogger.unsafeCreate[IO] + implicit val log = Slf4jLogger.getLogger[IO] resource[IO].use(_ => IO.never.as(ExitCode.Success)) } diff --git a/modules/core/src/main/scala/repo/CityRepo.scala b/modules/core/src/main/scala/repo/CityRepo.scala index 5be8583..93a2cd6 100644 --- a/modules/core/src/main/scala/repo/CityRepo.scala +++ b/modules/core/src/main/scala/repo/CityRepo.scala @@ -4,7 +4,7 @@ package demo.repo -import cats._ +import cats.effect._ import cats.implicits._ import doobie._ import doobie.implicits._ @@ -18,7 +18,7 @@ trait CityRepo[F[_]] { object CityRepo { - def fromTransactor[F[_]: Monad: Logger](xa: Transactor[F]): CityRepo[F] = + def fromTransactor[F[_]: Sync: Logger](xa: Transactor[F]): CityRepo[F] = new CityRepo[F] { val select: Fragment = @@ -37,4 +37,4 @@ object CityRepo { } -} \ No newline at end of file +} diff --git a/modules/core/src/main/scala/repo/CountryRepo.scala b/modules/core/src/main/scala/repo/CountryRepo.scala index 80a7f75..e2045eb 100644 --- a/modules/core/src/main/scala/repo/CountryRepo.scala +++ b/modules/core/src/main/scala/repo/CountryRepo.scala @@ -4,8 +4,8 @@ package demo.repo -import cats._ import cats.data._ +import cats.effect._ import cats.implicits._ import doobie._ import doobie.implicits._ @@ -21,7 +21,7 @@ trait CountryRepo[F[_]] { object CountryRepo { - def fromTransactor[F[_]: Monad: Logger](xa: Transactor[F]): CountryRepo[F] = + def fromTransactor[F[_]: Sync: Logger](xa: Transactor[F]): CountryRepo[F] = new CountryRepo[F] { val select: Fragment = @@ -56,4 +56,4 @@ object CountryRepo { } -} \ No newline at end of file +} diff --git a/modules/core/src/main/scala/repo/LanguageRepo.scala b/modules/core/src/main/scala/repo/LanguageRepo.scala index 6841326..a04e69c 100644 --- a/modules/core/src/main/scala/repo/LanguageRepo.scala +++ b/modules/core/src/main/scala/repo/LanguageRepo.scala @@ -4,8 +4,8 @@ package demo.repo -import cats._ import cats.data._ +import cats.effect.Sync import cats.implicits._ import doobie._ import doobie.implicits._ @@ -19,7 +19,7 @@ trait LanguageRepo[F[_]] { object LanguageRepo { - def fromTransactor[F[_]: Monad: Logger](xa: Transactor[F]): LanguageRepo[F] = + def fromTransactor[F[_]: Sync: Logger](xa: Transactor[F]): LanguageRepo[F] = new LanguageRepo[F] { val select: Fragment = @@ -51,4 +51,4 @@ object LanguageRepo { } -} \ No newline at end of file +} diff --git a/modules/core/src/main/scala/repo/MasterRepo.scala b/modules/core/src/main/scala/repo/MasterRepo.scala index 882f310..b8f9a58 100644 --- a/modules/core/src/main/scala/repo/MasterRepo.scala +++ b/modules/core/src/main/scala/repo/MasterRepo.scala @@ -4,7 +4,7 @@ package demo.repo -import cats._ +import cats.effect._ import doobie._ import io.chrisdavenport.log4cats.Logger @@ -16,11 +16,11 @@ final case class MasterRepo[F[_]]( object MasterRepo { - def fromTransactor[F[_]: Monad: Logger](xa: Transactor[F]): MasterRepo[F] = + def fromTransactor[F[_]: Sync: Logger](xa: Transactor[F]): MasterRepo[F] = MasterRepo( CityRepo.fromTransactor(xa), CountryRepo.fromTransactor(xa), LanguageRepo.fromTransactor(xa) ) -} \ No newline at end of file +} diff --git a/modules/core/src/main/scala/sangria/SangriaGraphQL.scala b/modules/core/src/main/scala/sangria/SangriaGraphQL.scala index 8562555..af0fae5 100644 --- a/modules/core/src/main/scala/sangria/SangriaGraphQL.scala +++ b/modules/core/src/main/scala/sangria/SangriaGraphQL.scala @@ -13,7 +13,6 @@ import _root_.sangria.marshalling.circe._ import _root_.sangria.parser.{ QueryParser, SyntaxError } import _root_.sangria.schema._ import _root_.sangria.validation._ -import cats._ import cats.effect._ import cats.implicits._ import io.circe.{ Json, JsonObject } @@ -70,8 +69,7 @@ object SangriaGraphQL { userContext: F[A], blockingExecutionContext: ExecutionContext )( - implicit F: MonadError[F, Throwable], - L: LiftIO[F] + implicit F: Async[F], ): GraphQL[F] = new GraphQL[F] { @@ -107,21 +105,22 @@ object SangriaGraphQL { variables: JsonObject )(implicit ec: ExecutionContext): F[Either[Json, Json]] = userContext.flatMap { ctx => - IO.fromFuture { - IO { - Executor.execute( - schema = schema, - deferredResolver = deferredResolver, - queryAst = query, - userContext = ctx, - variables = Json.fromJsonObject(variables), - operationName = operationName, - exceptionHandler = ExceptionHandler { - case (_, e) ⇒ HandledException(e.getMessage) - } - ) + F.async { (cb: Either[Throwable, Json] => Unit) => + Executor.execute( + schema = schema, + deferredResolver = deferredResolver, + queryAst = query, + userContext = ctx, + variables = Json.fromJsonObject(variables), + operationName = operationName, + exceptionHandler = ExceptionHandler { + case (_, e) ⇒ HandledException(e.getMessage) + } + ).onComplete { + case Success(value) => cb(Right(value)) + case Failure(error) => cb(Left(error)) } - } .to[F] + } } .attempt.flatMap { case Right(json) => F.pure(json.asRight) case Left(err: WithViolations) => fail(formatWithViolations(err)) diff --git a/project/build.properties b/project/build.properties index 0cd8b07..797e7cc 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.2.3 +sbt.version=1.3.10 diff --git a/project/plugins.sbt b/project/plugins.sbt index f975e14..f30b599 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,6 @@ -addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.4") -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0") +scalaVersion := "2.12.11" + +addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.0") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0") addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")