Using Sangria with Scala 3

138 Views Asked by At

Are there any examples of using Sangria with a Scala 3 program, or is that a non-starter? Using cross-compilation in SBT builds OK, but getting a NoSuchMethodError exception in Executor.execute when I send a query.

build.sbt looks like this:

val AkkaVersion = "2.6.21"
val SangriaAkkaHttpVersion = "0.0.4"

crossScalaVersions := Seq("2.13.5", "3.3.0")
ThisBuild / scalaVersion := "3.3.0"

("com.typesafe.akka" %% "akka-actor-typed" % AkkaVersion).cross(CrossVersion.for3Use2_13),
("com.typesafe.akka" %% "akka-stream-typed" % AkkaVersion).cross(CrossVersion.for3Use2_13),
("org.sangria-graphql" %% "sangria-akka-http-circe" % SangriaAkkaHttpVersion).cross(CrossVersion.for3Use2_13),

Any clues as to how to get this to work?

Error message:

java.lang.NoSuchMethodError: 'scala.runtime.BoxedUnit sangria.execution.Executor$.execute$default$4()'
    at XXX.graphql.GraphQlServer$$anon$1.applyOrElse(GraphQlServer.scala:55)
    at XXX.graphql.GraphQlServer$$anon$1.applyOrElse(GraphQlServer.scala:49)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
    at sangria.http.akka.SangriaAkkaHttp.$anonfun$prepareGraphQLPost$2(SangriaAkkaHttp.scala:137)
1

There are 1 best solutions below

3
Tim On

It turns out that the quickest solution was to switch from akka to pekko (painless) and modify the akka-http helpers for sangria to use pekko-http.

Specifically, I cloned sangria-akka-http-core, sangria-akka-http-circe, and akka-http-circe, and replaced import akka with import org.apache.pekko. Other than that the main issues were with the build process rather than the code.

Hopefully there will be official pekko versions of these libraries at some point.