diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 998f869..d60d6cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - scala: [2.12.14, 2.13.6] + scala: [2.12.14, 2.13.6, 3.0.0] java: [adopt@1.8] runs-on: ${{ matrix.os }} steps: @@ -77,7 +77,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - scala: [2.13.6] + scala: [3.0.0] java: [adopt@1.8] runs-on: ${{ matrix.os }} steps: @@ -123,6 +123,16 @@ jobs: tar xf targets.tar rm targets.tar + - name: Download target directories (3.0.0) + uses: actions/download-artifact@v2 + with: + name: target-${{ matrix.os }}-3.0.0-${{ matrix.java }} + + - name: Inflate target directories (3.0.0) + run: | + tar xf targets.tar + rm targets.tar + - env: PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} PGP_SECRET: ${{ secrets.PGP_SECRET }} diff --git a/build.sbt b/build.sbt index 9de82ac..eb249b4 100644 --- a/build.sbt +++ b/build.sbt @@ -1,13 +1,23 @@ +val isScala3 = Def.setting( + CrossVersion.partialVersion(scalaVersion.value).exists(_._1 == 3) +) + name := "sangria-marshalling-api" organization := "org.sangria-graphql" -mimaPreviousArtifacts := Set("org.sangria-graphql" %% "sangria-marshalling-api" % "1.0.5") +mimaPreviousArtifacts := { + if (isScala3.value) + Set.empty + else + Set("org.sangria-graphql" %% "sangria-marshalling-api" % "1.0.5") +} description := "Sangria Marshalling API" homepage := Some(url("https://sangria-graphql.github.io/")) -licenses := Seq("Apache License, ASL Version 2.0" → url("https://www.apache.org/licenses/LICENSE-2.0")) +licenses := Seq( + "Apache License, ASL Version 2.0" → url("https://www.apache.org/licenses/LICENSE-2.0")) // sbt-github-actions needs configuration in `ThisBuild` -ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6") +ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6", "3.0.0") ThisBuild / scalaVersion := crossScalaVersions.value.last ThisBuild / githubWorkflowPublishTargetBranches := List() ThisBuild / githubWorkflowBuildPreamble ++= List( @@ -15,8 +25,12 @@ ThisBuild / githubWorkflowBuildPreamble ++= List( WorkflowStep.Sbt(List("scalafmtCheckAll"), name = Some("Check formatting")) ) scalacOptions ++= Seq("-deprecation", "-feature") - -scalacOptions += "-target:jvm-1.8" +scalacOptions ++= { + if (isScala3.value) + Seq("-Xtarget:8") + else + Seq("-target:jvm-1.8") +} javacOptions ++= Seq("-source", "8", "-target", "8") libraryDependencies ++= Seq( @@ -42,11 +56,16 @@ ThisBuild / githubWorkflowPublish := Seq( startYear := Some(2016) organizationHomepage := Some(url("https://github.com/sangria-graphql")) -developers := Developer("OlegIlyenko", "Oleg Ilyenko", "", url("https://github.com/OlegIlyenko")) :: Nil -scmInfo := Some(ScmInfo( - browseUrl = url("https://github.com/sangria-graphql/sangria-marshalling-api"), - connection = "scm:git:git@github.com:sangria-graphql/sangria-marshalling-api.git" -)) +developers := Developer( + "OlegIlyenko", + "Oleg Ilyenko", + "", + url("https://github.com/OlegIlyenko")) :: Nil +scmInfo := Some( + ScmInfo( + browseUrl = url("https://github.com/sangria-graphql/sangria-marshalling-api"), + connection = "scm:git:git@github.com:sangria-graphql/sangria-marshalling-api.git" + )) // nice *magenta* prompt! ThisBuild / shellPrompt := { state => diff --git a/src/main/scala/sangria/marshalling/FromInput.scala b/src/main/scala/sangria/marshalling/FromInput.scala index b0df4dc..4791b72 100644 --- a/src/main/scala/sangria/marshalling/FromInput.scala +++ b/src/main/scala/sangria/marshalling/FromInput.scala @@ -12,14 +12,14 @@ trait FromInput[Val] { object FromInput { private object ScalarFromInput extends FromInput[Any] { - val marshaller = CoercedScalaResultMarshaller.default - def fromResult(node: marshaller.Node) = node + val marshaller: CoercedScalaResultMarshaller = CoercedScalaResultMarshaller.default + def fromResult(node: marshaller.Node): marshaller.Node = node } class SeqFromInput[T](delegate: FromInput[T]) extends FromInput[Seq[T]] { - val marshaller = delegate.marshaller + val marshaller: ResultMarshaller = delegate.marshaller - def fromResult(node: marshaller.Node) = + def fromResult(node: marshaller.Node): Seq[T] = node .asInstanceOf[Seq[Any]] .map { @@ -33,14 +33,17 @@ object FromInput { import sangria.util.tag._ - implicit def coercedScalaInput[T] = + implicit def coercedScalaInput[T]: FromInput[T @@ CoercedScalaResult] = ScalarFromInput.asInstanceOf[FromInput[T @@ CoercedScalaResult]] - implicit def defaultInput[T] = ScalarFromInput.asInstanceOf[FromInput[Map[String, Any]]] - implicit def inputObjectResultInput[T](implicit ev: FromInput[T]) = + implicit def defaultInput[T]: FromInput[Map[String, Any]] = + ScalarFromInput.asInstanceOf[FromInput[Map[String, Any]]] + implicit def inputObjectResultInput[T](implicit + ev: FromInput[T]): FromInput[T @@ InputObjectResult] = ev.asInstanceOf[FromInput[T @@ InputObjectResult]] - implicit def optionInput[T](implicit ev: FromInput[T]) = ev.asInstanceOf[FromInput[Option[T]]] - implicit def seqInput[T](implicit ev: FromInput[T]) = new SeqFromInput[T](ev) + implicit def optionInput[T](implicit ev: FromInput[T]): FromInput[Option[T]] = + ev.asInstanceOf[FromInput[Option[T]]] + implicit def seqInput[T](implicit ev: FromInput[T]): SeqFromInput[T] = new SeqFromInput[T](ev) trait CoercedScalaResult trait InputObjectResult diff --git a/src/main/scala/sangria/marshalling/InputUnmarshaller.scala b/src/main/scala/sangria/marshalling/InputUnmarshaller.scala index 0a8c33a..067e980 100644 --- a/src/main/scala/sangria/marshalling/InputUnmarshaller.scala +++ b/src/main/scala/sangria/marshalling/InputUnmarshaller.scala @@ -1,6 +1,7 @@ package sangria.marshalling import sangria.util.tag +import sangria.util.tag.@@ import scala.annotation.implicitNotFound @@ -54,5 +55,6 @@ object InputUnmarshaller { def emptyMapVars = tag[ScalaInput](Map.empty[String, Any]) - implicit def scalaInputUnmarshaller[T] = scalaMarshalling.scalaInputUnmarshaller[T] + implicit def scalaInputUnmarshaller[T]: InputUnmarshaller[T @@ ScalaInput] = + scalaMarshalling.scalaInputUnmarshaller[T] } diff --git a/src/main/scala/sangria/marshalling/MarshallingUtil.scala b/src/main/scala/sangria/marshalling/MarshallingUtil.scala index c017637..0abf2fb 100644 --- a/src/main/scala/sangria/marshalling/MarshallingUtil.scala +++ b/src/main/scala/sangria/marshalling/MarshallingUtil.scala @@ -20,8 +20,8 @@ object MarshallingUtil { rm.mapNode(builder) case list if iu.isListNode(list) => rm.mapAndMarshal(iu.getListValue(list), (elem: In) => convert(elem).asInstanceOf[rm.Node]) - case enum if iu.isEnumNode(enum) && iu.getScalaScalarValue(enum).isInstanceOf[String] => - rm.enumNode(iu.getScalaScalarValue(enum).asInstanceOf[String], "Conversion") + case enums if iu.isEnumNode(enums) && iu.getScalaScalarValue(enums).isInstanceOf[String] => + rm.enumNode(iu.getScalaScalarValue(enums).asInstanceOf[String], "Conversion") case scalar if iu.isScalarNode(scalar) => rm.scalarNode(iu.getScalaScalarValue(scalar), "Conversion", Set.empty) case variable if iu.isVariableNode(variable) => diff --git a/src/main/scala/sangria/marshalling/ResultMarshaller.scala b/src/main/scala/sangria/marshalling/ResultMarshaller.scala index defd369..6375aaa 100644 --- a/src/main/scala/sangria/marshalling/ResultMarshaller.scala +++ b/src/main/scala/sangria/marshalling/ResultMarshaller.scala @@ -56,7 +56,8 @@ trait ResultMarshaller { } object ResultMarshaller { - implicit val defaultResultMarshaller = scalaMarshalling.scalaResultMarshaller + implicit val defaultResultMarshaller: ScalaResultMarshaller = + scalaMarshalling.scalaResultMarshaller } /** Alters the behaviour of the executor and marshals raw (in-scala coerced representation) or scalar values and enums. diff --git a/src/main/scala/sangria/marshalling/ToInput.scala b/src/main/scala/sangria/marshalling/ToInput.scala index ced6ff5..669aea2 100644 --- a/src/main/scala/sangria/marshalling/ToInput.scala +++ b/src/main/scala/sangria/marshalling/ToInput.scala @@ -13,18 +13,21 @@ trait ToInput[Val, Raw] { object ToInput { class ScalarToInput[T] extends ToInput[T, T @@ ScalaInput] { - def toInput(value: T) = (ScalaInput.scalaInput(value), InputUnmarshaller.scalaInputUnmarshaller) + def toInput(value: T): (T @@ ScalaInput, InputUnmarshaller[T @@ ScalaInput]) = + (ScalaInput.scalaInput(value), InputUnmarshaller.scalaInputUnmarshaller) } - implicit def normalScalaInput[T] = new ToInput[T @@ ScalaInput, T @@ ScalaInput] { - def toInput(value: T @@ ScalaInput) = (value, InputUnmarshaller.scalaInputUnmarshaller) - } + implicit def normalScalaInput[T]: ToInput[T @@ ScalaInput, T @@ ScalaInput] = + new ToInput[T @@ ScalaInput, T @@ ScalaInput] { + def toInput(value: T @@ ScalaInput): (T @@ ScalaInput, InputUnmarshaller[T @@ ScalaInput]) = + (value, InputUnmarshaller.scalaInputUnmarshaller) + } - implicit val intInput = new ScalarToInput[Int] - implicit val bigDecimalInput = new ScalarToInput[BigDecimal] - implicit val bigIntInput = new ScalarToInput[BigInt] - implicit val longInput = new ScalarToInput[Long] - implicit val floatInput = new ScalarToInput[Double] - implicit val booleanInput = new ScalarToInput[Boolean] - implicit val stringInput = new ScalarToInput[String] + implicit val intInput: ScalarToInput[Int] = new ScalarToInput[Int] + implicit val bigDecimalInput: ScalarToInput[BigDecimal] = new ScalarToInput[BigDecimal] + implicit val bigIntInput: ScalarToInput[BigInt] = new ScalarToInput[BigInt] + implicit val longInput: ScalarToInput[Long] = new ScalarToInput[Long] + implicit val floatInput: ScalarToInput[Double] = new ScalarToInput[Double] + implicit val booleanInput: ScalarToInput[Boolean] = new ScalarToInput[Boolean] + implicit val stringInput: ScalarToInput[String] = new ScalarToInput[String] } diff --git a/src/main/scala/sangria/marshalling/scalaMarshalling.scala b/src/main/scala/sangria/marshalling/scalaMarshalling.scala index cced375..c3e754b 100644 --- a/src/main/scala/sangria/marshalling/scalaMarshalling.scala +++ b/src/main/scala/sangria/marshalling/scalaMarshalling.scala @@ -7,7 +7,7 @@ import scala.collection.immutable.ListMap object scalaMarshalling { private val scalaScalaUnmarshallerGen = new ScalaInputUnmarshaller[Any] - implicit val scalaResultMarshaller = new ScalaResultMarshaller + implicit val scalaResultMarshaller: ScalaResultMarshaller = new ScalaResultMarshaller implicit object ScalaMarshallerForType extends ResultMarshallerForType[Any @@ ScalaInput] { val marshaller = scalaResultMarshaller