Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 3 Support #847

Merged
merged 33 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ec9c58b
Initial setup
ghostdogpr Apr 14, 2021
f685e71
fmt
ghostdogpr Apr 14, 2021
a141979
Fix CI
ghostdogpr Apr 14, 2021
81d8905
Move stuff
ghostdogpr Apr 14, 2021
4963988
Simplify
ghostdogpr Apr 14, 2021
0c160f4
Fix CI
ghostdogpr Apr 14, 2021
159cced
Upgrade Scala 3 to RC2
ghostdogpr Apr 14, 2021
382fbc7
gqldoc macro for Scala 3 (#849)
javimartinez Apr 17, 2021
2aacb2e
Implement derivation for SubscriptionSchema
ghostdogpr May 1, 2021
4a6b73f
Implement ArgBuilder derivation
ghostdogpr May 2, 2021
402f66d
Polishing
ghostdogpr May 2, 2021
935b00c
Schema derivation
ghostdogpr May 2, 2021
4c85a36
Remove test code
ghostdogpr May 2, 2021
6398ac6
WIP Schema
ghostdogpr May 2, 2021
04a3760
Enable tests on Scala 3
ghostdogpr May 2, 2021
b0b85ce
Uncomment some tests
ghostdogpr May 2, 2021
04ded6d
Remove logic for value classes since it's not supported
ghostdogpr May 3, 2021
61aff5e
Fix ExecutionSpec
ghostdogpr May 3, 2021
30e3e96
Fix ValidationSchemaSpec
ghostdogpr May 3, 2021
ad4b5b6
Enable client on Scala 3
ghostdogpr May 4, 2021
665b1f3
Remove federation from Scala 3
ghostdogpr May 4, 2021
d2a5ae0
Enable Scala 3 on Caliban Client for Scala.js
ghostdogpr May 5, 2021
0d34d17
Simplify derivation and make it work with Scala enums
ghostdogpr May 5, 2021
fb3b3f0
Exclude test for now
ghostdogpr May 5, 2021
f5c670d
Remove import
ghostdogpr May 5, 2021
e203073
cats-parse scala3 (#850)
timzaak May 7, 2021
fd9a96c
Enable tests
ghostdogpr May 7, 2021
11cbbd5
Unignore last ignored test
ghostdogpr May 7, 2021
7c76866
Merge branch 'master' into scala3
ghostdogpr May 10, 2021
d6efe2b
Fix merge issue
ghostdogpr May 10, 2021
156979f
Cosmetic changes
ghostdogpr May 10, 2021
6b00ff6
fmt
ghostdogpr May 10, 2021
6af3e1b
Update docs
ghostdogpr May 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Polishing
  • Loading branch information
ghostdogpr committed May 2, 2021
commit 402f66da4586620cc847073dee385e2456b1d4be
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait ArgBuilderDerivation {
inline erasedValue[(Label, A)] match {
case (_: (name *: names), _: (t *: ts)) =>
val label = constValue[name].toString
val annotations = Macros.anns[t]
val annotations = Macros.annotations[t]
val builder = summonInline[ArgBuilder[t]].asInstanceOf[ArgBuilder[Any]]
(label, annotations, builder) :: recurse[names, ts]
case (_: EmptyTuple, _) => Nil
Expand Down Expand Up @@ -47,7 +47,7 @@ trait ArgBuilderDerivation {

case m: Mirror.ProductOf[A] =>
lazy val fields = recurse[m.MirroredElemLabels, m.MirroredElemTypes]
lazy val annotations = Macros.paramAnns[A].to(Map)
lazy val annotations = Macros.paramAnnotations[A].to(Map)
new ArgBuilder[A] {
def build(input: InputValue): Either[ExecutionError, A] = {
fields.map { (label, _, builder) =>
Expand Down
26 changes: 13 additions & 13 deletions core/src/main/scala-3/caliban/schema/macros/Macros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ package caliban.schema.macros
import scala.quoted.*

private[caliban] object Macros {
inline def anns[T]: List[Any] = ${anns[T]}
inline def paramAnns[T]: List[(String, List[Any])] = ${paramAnns[T]}
inline def annotations[T]: List[Any] = ${annotationsImpl[T]}
inline def paramAnnotations[T]: List[(String, List[Any])] = ${paramAnnotationsImpl[T]}

def paramAnns[T: Type](using qctx: Quotes): Expr[List[(String, List[Any])]] = {
def annotationsImpl[T: Type](using qctx: Quotes): Expr[List[Any]] = {
import qctx.reflect.*

val tpe = TypeRepr.of[T]

Expr.ofList {
tpe.typeSymbol.primaryConstructor.paramSymss.flatten.map { field =>
Expr(field.name) -> field.annotations.filter { a =>
a.tpe.typeSymbol.maybeOwner.isNoSymbol ||
a.tpe.typeSymbol.owner.fullName != "scala.annotation.internal"
}.map(_.asExpr.asInstanceOf[Expr[Any]])
}.filter(_._2.nonEmpty).map { (name, anns) => Expr.ofTuple(name, Expr.ofList(anns)) }
tpe.typeSymbol.annotations.filter { a =>
a.tpe.typeSymbol.maybeOwner.isNoSymbol || a.tpe.typeSymbol.owner.fullName != "scala.annotation.internal"
}.map(_.asExpr.asInstanceOf[Expr[Any]])
}
}

def anns[T: Type](using qctx: Quotes): Expr[List[Any]] = {
def paramAnnotationsImpl[T: Type](using qctx: Quotes): Expr[List[(String, List[Any])]] = {
import qctx.reflect.*

val tpe = TypeRepr.of[T]

Expr.ofList {
tpe.typeSymbol.annotations.filter { a =>
a.tpe.typeSymbol.maybeOwner.isNoSymbol || a.tpe.typeSymbol.owner.fullName != "scala.annotation.internal"
}.map(_.asExpr.asInstanceOf[Expr[Any]])
tpe.typeSymbol.primaryConstructor.paramSymss.flatten.map { field =>
Expr(field.name) -> field.annotations.filter { a =>
a.tpe.typeSymbol.maybeOwner.isNoSymbol ||
a.tpe.typeSymbol.owner.fullName != "scala.annotation.internal"
}.map(_.asExpr.asInstanceOf[Expr[Any]])
}.filter(_._2.nonEmpty).map { (name, anns) => Expr.ofTuple(name, Expr.ofList(anns)) }
}
}
}