Skip to content

Commit

Permalink
Merge pull request #196 from sangria-graphql/scala_3
Browse files Browse the repository at this point in the history
cross-compile to scala 3
  • Loading branch information
yanns authored Oct 11, 2022
2 parents c35b725 + 84eca68 commit d2eeef6
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 31 deletions.
12 changes: 11 additions & 1 deletion .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.17, 2.13.8]
scala: [2.12.17, 2.13.8, 3.2.0]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -127,6 +127,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.2.0)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-3.2.0-${{ matrix.java }}

- name: Inflate target directories (3.2.0)
run: |
tar xf targets.tar
rm targets.tar
- env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
Expand Down
28 changes: 22 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
import com.typesafe.tools.mima.core._

name := "sangria-relay"
organization := "org.sangria-graphql"
mimaPreviousArtifacts := Set("org.sangria-graphql" %% "sangria-relay" % "2.1.0")

description := "Sangria Relay Support"
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"))

val isScala3 = Def.setting(
CrossVersion.partialVersion(scalaVersion.value).exists(_._1 == 3)
)

// sbt-github-actions needs configuration in `ThisBuild`
ThisBuild / crossScalaVersions := Seq("2.12.17", "2.13.8")
ThisBuild / scalaVersion := crossScalaVersions.value.last
ThisBuild / crossScalaVersions := Seq("2.12.17", "2.13.8", "3.2.0")
ThisBuild / scalaVersion := crossScalaVersions.value.tail.head
ThisBuild / githubWorkflowBuildPreamble ++= List(
WorkflowStep.Sbt(List("mimaReportBinaryIssues"), name = Some("Check binary compatibility")),
WorkflowStep.Sbt(List("scalafmtCheckAll"), name = Some("Check formatting"))
)

scalacOptions ++= Seq("-deprecation", "-feature", "-target:jvm-1.8")
scalacOptions ++= Seq("-deprecation", "-feature")
scalacOptions += { if (isScala3.value) "-Xtarget:8" else "-target:jvm-1.8" }
javacOptions ++= Seq("-source", "8", "-target", "8")

libraryDependencies ++= Seq(
"org.sangria-graphql" %% "sangria" % "3.2.0",
"org.scalatest" %% "scalatest" % "3.2.13" % Test)
"org.sangria-graphql" %% "sangria" % "3.4.0",
"org.scalatest" %% "scalatest" % "3.2.14" % Test)

mimaPreviousArtifacts := {
if (isScala3.value) Set.empty
else Set("org.sangria-graphql" %% "sangria-relay" % "2.1.0")
}
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[IncompatibleResultTypeProblem](
"sangria.relay.Connection.definitionWithEdge$default$5"),
ProblemFilters.exclude[IncompatibleMethTypeProblem]("sangria.relay.Connection.definitionWithEdge")
)

// Publishing
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
Expand Down
16 changes: 10 additions & 6 deletions src/main/scala/sangria/relay/Connection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sangria.execution.UserFacingError
import sangria.relay.util.Base64
import sangria.schema._

import scala.annotation.implicitNotFound
import scala.annotation.{implicitNotFound, tailrec}
import scala.concurrent.{ExecutionContext, Future}
import scala.language.higherKinds
import scala.reflect.ClassTag
Expand All @@ -25,6 +25,7 @@ object Connection {
val All = Before :: After :: First :: Last :: Nil
}

@tailrec
def isValidNodeType[Val](nodeType: OutputType[Val]): Boolean = nodeType match {
case _: ScalarType[_] | _: EnumType[_] | _: CompositeType[_] => true
case OptionType(ofType) => isValidNodeType(ofType)
Expand All @@ -36,7 +37,9 @@ object Connection {
nodeType: OutputType[Val],
edgeFields: => List[Field[Ctx, Edge[Val]]] = Nil,
connectionFields: => List[Field[Ctx, Conn[Val]]] = Nil
)(implicit connEv: ConnectionLike[Conn, PageInfo, Val, Edge[Val]], classEv: ClassTag[Conn[Val]]) =
)(implicit
connEv: ConnectionLike[Conn, PageInfo, Val, Edge[Val]],
classEv: ClassTag[Conn[Val]]): ConnectionDefinition[Ctx, Conn[Val], Val, Edge[Val]] =
definitionWithEdge[Ctx, DefaultPageInfo, Conn, Val, Edge[Val]](
name,
nodeType,
Expand All @@ -48,7 +51,7 @@ object Connection {
nodeType: OutputType[Val],
edgeFields: => List[Field[Ctx, E]] = Nil,
connectionFields: => List[Field[Ctx, Conn[Val]]] = Nil,
pageInfoType: OutputType[P] = DefaultPageInfo.pageInfoType
pageInfoType: Option[OutputType[P]] = None
)(implicit
connEv: ConnectionLike[Conn, P, Val, E],
classEv: ClassTag[Conn[Val]],
Expand Down Expand Up @@ -80,9 +83,10 @@ object Connection {
List[Field[Ctx, Conn[Val]]](
Field(
"pageInfo",
pageInfoType,
pageInfoType.getOrElse(DefaultPageInfo.pageInfoType[Ctx, P]),
Some("Information to aid in pagination."),
resolve = ctx => connEv.pageInfo(ctx.value)),
resolve = ctx => connEv.pageInfo(ctx.value)
),
Field(
"edges",
OptionType(ListType(OptionType(edgeType))),
Expand Down Expand Up @@ -208,7 +212,7 @@ case class DefaultPageInfo(

object DefaultPageInfo {
def pageInfoType[Ctx, P <: PageInfo: ClassTag]: ObjectType[Ctx, P] =
ObjectType(
ObjectType[Ctx, P](
"PageInfo",
"Information about pagination in a connection.",
() =>
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/sangria/relay/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ trait Node {
}

object Node {
implicit def identifiableNodeType[Ctx, T](implicit ev: IdentifiableNode[Ctx, T]) =
implicit def identifiableNodeType[Ctx, T](implicit
ev: IdentifiableNode[Ctx, T]): PossibleType[Node, T] =
PossibleType.create[Node, T]

val GlobalIdFieldName = "id"
Expand Down
18 changes: 10 additions & 8 deletions src/test/scala/sangria/relay/ConnectionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ConnectionSpec extends AnyWordSpec with Matchers with AwaitSupport {
val UserType: ObjectType[Repo, User] = ObjectType(
"User",
() =>
fields(
fields[Repo, User](
Field("name", OptionType(StringType), resolve = _.value.name),
Field(
"pets",
Expand Down Expand Up @@ -170,13 +170,15 @@ class ConnectionSpec extends AnyWordSpec with Matchers with AwaitSupport {
}

"Not allow list node type" in {
an[IllegalArgumentException] should be thrownBy
Connection.definition[Repo, Connection, Seq[Pet]]("Pet", ListType(PetType))

an[IllegalArgumentException] should be thrownBy
Connection.definition[Repo, Connection, Option[Seq[Pet]]](
"Pet",
OptionType(ListType(PetType)))
assertTypeError("""
|Connection.definition[Repo, Connection, Seq[Pet]]("Pet", ListType(PetType))
|""".stripMargin)

assertTypeError("""
|Connection.definition[Repo, Connection, Option[Seq[Pet]]](
| "Pet",
| OptionType(ListType(PetType)))
|""".stripMargin)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ConnectionWithCustomPageInfoSpec extends AnyWordSpec with Matchers with Aw
*/
case class CustomConnection[T](pageInfo: CustomPageInfo, edges: Seq[Edge[T]])

implicit def customConnectionLike[T] =
implicit
def customConnectionLike[T]: ConnectionLike[CustomConnection, CustomPageInfo, T, Edge[T]] =
new ConnectionLike[CustomConnection, CustomPageInfo, T, Edge[T]] {
override def pageInfo(conn: CustomConnection[T]): CustomPageInfo = conn.pageInfo
override def edges(conn: CustomConnection[T]): Seq[Edge[T]] = conn.edges
Expand Down Expand Up @@ -74,7 +75,7 @@ class ConnectionWithCustomPageInfoSpec extends AnyWordSpec with Matchers with Aw
val TaskType: ObjectType[Repo, Task] = ObjectType(
"Task",
() =>
fields(
fields[Repo, Task](
Field("id", StringType, resolve = _.value.id),
Field("userId", StringType, resolve = _.value.userId),
Field("description", StringType, resolve = _.value.description)
Expand All @@ -85,7 +86,7 @@ class ConnectionWithCustomPageInfoSpec extends AnyWordSpec with Matchers with Aw
ObjectType(
"CustomPageInfo",
() =>
fields(
fields[Repo, CustomPageInfo](
Field(
"hasNextPage",
BooleanType,
Expand Down Expand Up @@ -118,7 +119,7 @@ class ConnectionWithCustomPageInfoSpec extends AnyWordSpec with Matchers with Aw
Connection.definitionWithEdge[Repo, CustomPageInfo, CustomConnection, Task, Edge[Task]](
name = "Task",
nodeType = TaskType,
pageInfoType = customPageInfoType
pageInfoType = Some(customPageInfoType)
)

private object Args {
Expand All @@ -129,7 +130,7 @@ class ConnectionWithCustomPageInfoSpec extends AnyWordSpec with Matchers with Aw
val UserType: ObjectType[Repo, User] = ObjectType(
"User",
() =>
fields(
fields[Repo, User](
Field("id", StringType, resolve = _.value.id),
Field("name", StringType, resolve = _.value.name),
Field(
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/sangria/relay/ConnectionWithEdgeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class ConnectionWithEdgeSpec extends AnyWordSpec with Matchers with AwaitSupport
val UserType: ObjectType[Repo, User] = ObjectType(
"User",
() =>
fields(
fields[Repo, User](
Field("id", StringType, resolve = _.value.id),
Field("name", StringType, resolve = _.value.name)
))

val AccountType: ObjectType[Repo, Account] = ObjectType(
"Account",
() =>
fields(
fields[Repo, Account](
Field("id", StringType, resolve = _.value.id),
Field("number", StringType, resolve = _.value.number),
Field(
Expand All @@ -94,7 +94,7 @@ class ConnectionWithEdgeSpec extends AnyWordSpec with Matchers with AwaitSupport
val RoleType: ObjectType[Repo, Role] = ObjectType(
"Role",
() =>
fields(
fields[Repo, Role](
Field("id", StringType, resolve = _.value.id),
Field("display", StringType, resolve = _.value.display)
))
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/sangria/relay/util/DebugUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object DebugUtil {
}
}

private implicit val conf = myPrettifier
private implicit val conf: Prettifier = myPrettifier

def prettyRender(obj: Any) = obj.pretty

Expand Down

0 comments on commit d2eeef6

Please sign in to comment.