Skip to content

Commit

Permalink
Add scala 3 support to federation (#997)
Browse files Browse the repository at this point in the history
* Add scala 3 support to federation

* Fix CI

* Render directives alphabetically
  • Loading branch information
ghostdogpr authored Aug 7, 2021
1 parent 2750d65 commit e1fa99a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- checkout
- restore_cache:
key: sbtcache
- run: sbt ++3.0.1! core/test catsInterop/compile monixInterop/compile clientJVM/test clientJS/compile zioHttp/compile tapirInterop/test http4s/test
- run: sbt ++3.0.1! core/test catsInterop/compile monixInterop/compile clientJVM/test clientJS/compile zioHttp/compile tapirInterop/test http4s/test federation/test
- save_cache:
key: sbtcache
paths:
Expand Down
7 changes: 2 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -436,21 +436,18 @@ lazy val federation = project
.settings(commonSettings)
.dependsOn(core % "compile->compile;test->test")
.settings(
crossScalaVersions -= scala3,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework")),
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test,
compilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")
"dev.zio" %% "zio-test-sbt" % zioVersion % Test
),
Compile / PB.targets := Seq(
scalapb.gen(grpc = false) -> (Compile / sourceManaged).value / "scalapb"
),
libraryDependencies ++= Seq(
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf"
),
scalacOptions += "-Ywarn-unused:-locals"
)
)

val commonSettings = Def.settings(
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/caliban/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ object Rendering {
private def renderDirectives(directives: Option[List[Directive]]) =
directives.fold("") {
case Nil => ""
case d => d.map(renderDirective).mkString(" ", " ", "")
case d => d.sortBy(_.name).map(renderDirective).mkString(" ", " ", "")
}

private def renderField(field: __Field): String =
Expand Down
4 changes: 2 additions & 2 deletions federation/src/main/scala/caliban/federation/Federation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ trait Federation {
val resolvers = resolver +: otherResolvers.toList

val genericSchema = new GenericSchema[R] {}
import genericSchema._
import genericSchema.{ gen, _ }

implicit val entitySchema: Schema[R, _Entity] = new Schema[R, _Entity] {
override def toType(isInput: Boolean, isSubscription: Boolean): __Type =
Expand Down Expand Up @@ -178,7 +178,7 @@ object Federation {
case InputValue.ObjectValue(fields) =>
fields.get("representations").toRight(ExecutionError("_Any must contain a __typename value")).flatMap {
case InputValue.ListValue(values) =>
traverseEither(values.map(anyArgBuilder.build)).map(RepresentationsArgs)
traverseEither(values.map(anyArgBuilder.build)).map(RepresentationsArgs.apply)
case other => Left(ExecutionError(s"Can't build a representations from input $other"))
}
case other => Left(ExecutionError(s"Can't build a representations from input $other"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ object ApolloFederatedTracing {
)
)(
for {
startNano <- clock.nanoTime
_ <- ref.update(_.copy(startTime = startNano))
((start, end), result) <- process(request).summarized(clock.currentTime(TimeUnit.MILLISECONDS))((_, _))
endNano <- clock.nanoTime
tracing <- ref.get
startNano <- clock.nanoTime
_ <- ref.update(_.copy(startTime = startNano))
response <- process(request).summarized(clock.currentTime(TimeUnit.MILLISECONDS))((_, _))
((start, end), result) = response
endNano <- clock.nanoTime
tracing <- ref.get
} yield {
val root = Trace(
startTime = Some(toTimestamp(start)),
Expand Down Expand Up @@ -89,32 +90,33 @@ object ApolloFederatedTracing {
.flatMap(
if (_)
for {
((startTime, endTime), summarized) <- query.either.summarized(clock.nanoTime)((_, _))
id = Node.Id.ResponseName(fieldInfo.name)
result <- ZQuery.fromEffect(
ref.update(state =>
state.copy(
root = state.root.insert(
(Left(fieldInfo.name) :: fieldInfo.path).toVector,
Node(
id = id,
startTime = startTime - state.startTime,
endTime = endTime - state.startTime,
`type` = fieldInfo.details.fieldType.toType().toString,
parentType = fieldInfo.details.parentType.map(_.toType().toString) getOrElse "",
originalFieldName = fieldInfo.details.alias
.map(_ => fieldInfo.details.name) getOrElse "",
error = summarized.left.toOption.collectFirst { case e: ExecutionError =>
Error(
e.getMessage(),
location = e.locationInfo.map(l => Location(l.line, l.column)).toSeq
)
}.toSeq
)
)
)
) *> ZIO.fromEither(summarized)
)
response <- query.either.summarized(clock.nanoTime)((_, _))
((startTime, endTime), summarized) = response
id = Node.Id.ResponseName(fieldInfo.name)
result <- ZQuery.fromEffect(
ref.update(state =>
state.copy(
root = state.root.insert(
(Left(fieldInfo.name) :: fieldInfo.path).toVector,
Node(
id = id,
startTime = startTime - state.startTime,
endTime = endTime - state.startTime,
`type` = fieldInfo.details.fieldType.toType().toString,
parentType = fieldInfo.details.parentType.map(_.toType().toString) getOrElse "",
originalFieldName = fieldInfo.details.alias
.map(_ => fieldInfo.details.name) getOrElse "",
error = summarized.left.toOption.collectFirst { case e: ExecutionError =>
Error(
e.getMessage(),
location = e.locationInfo.map(l => Location(l.line, l.column)).toSeq
)
}.toSeq
)
)
)
) *> ZIO.fromEither(summarized)
)
} yield result
else query
)
Expand All @@ -132,7 +134,7 @@ object ApolloFederatedTracing {
val empty: NodeTrie = NodeTrie(None, Map.empty[Either[String, Int], NodeTrie])

private def newEmptyNode(id: Either[String, Int]) =
Node(id = id.fold(Node.Id.ResponseName, Node.Id.Index))
Node(id = id.fold(Node.Id.ResponseName.apply, Node.Id.Index.apply))

private def loopInsert(trie: NodeTrie, path: VPath, value: Node, step: Int): NodeTrie =
if (step == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ object FederationSpec extends DefaultRunnableSpec {
val query = gqldoc("""{ _service { sdl } }""")
assertM(interpreter.flatMap(_.execute(query)).map(d => d.data.toString))(
containsString(
"""type Orphan @key(fields: \"name\") @extends {\n name: String! @external\n nicknames: [String!]!\n child: OrphanChild!\n}"""
"""type Orphan @extends @key(fields: \"name\") {\n name: String! @external\n nicknames: [String!]!\n child: OrphanChild!\n}"""
) &&
containsString(
"""type OrphanChild {\n id: String!\n}"""
Expand Down

0 comments on commit e1fa99a

Please sign in to comment.