Skip to content

Commit

Permalink
Merge pull request #65 from sh0hei/hello-scala3
Browse files Browse the repository at this point in the history
Hello, Scala3 🎉
  • Loading branch information
sh0hei authored May 31, 2021
2 parents e0ffc22 + 77740e6 commit 715f667
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 37 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.6]
scala: [3.0.0]
java: [[email protected]]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -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 }}
Expand Down
39 changes: 29 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
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(
WorkflowStep.Sbt(List("mimaReportBinaryIssues"), name = Some("Check binary compatibility")),
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(
Expand All @@ -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:[email protected]: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:[email protected]:sangria-graphql/sangria-marshalling-api.git"
))

// nice *magenta* prompt!
ThisBuild / shellPrompt := { state =>
Expand Down
21 changes: 12 additions & 9 deletions src/main/scala/sangria/marshalling/FromInput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/sangria/marshalling/InputUnmarshaller.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sangria.marshalling

import sangria.util.tag
import sangria.util.tag.@@

import scala.annotation.implicitNotFound

Expand Down Expand Up @@ -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]
}
4 changes: 2 additions & 2 deletions src/main/scala/sangria/marshalling/MarshallingUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/sangria/marshalling/ResultMarshaller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 14 additions & 11 deletions src/main/scala/sangria/marshalling/ToInput.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
2 changes: 1 addition & 1 deletion src/main/scala/sangria/marshalling/scalaMarshalling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 715f667

Please sign in to comment.