-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve laziness of typeclass derivation (#658)
* Improve laziness of typeclass derivation * Fix build for 2.12 * Rename Exported to Derived * Improve error messages * Renaming * Renaming + improve docs
- Loading branch information
1 parent
f47d69d
commit 7d69874
Showing
6 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package caliban.schema | ||
|
||
import scala.annotation.implicitNotFound | ||
|
||
@implicitNotFound( | ||
"""Cannot find a ${T}. | ||
Caliban derives a Schema automatically for basic Scala types, case classes and sealed traits, but | ||
you need to manually provide an implicit Schema for other types that could be nested inside your type. | ||
If you use a custom type as an argument, you also need to provide an implicit ArgBuilder for that type. | ||
See https://ghostdogpr.github.io/caliban/docs/schema.html for more information. | ||
""" | ||
) | ||
case class Derived[T](schema: T) extends AnyVal |
16 changes: 16 additions & 0 deletions
16
macros/src/main/scala/caliban/schema/DerivedMagnolia.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package caliban.schema | ||
|
||
object DerivedMagnolia { | ||
import magnolia.Magnolia | ||
|
||
import scala.reflect.macros.whitebox | ||
|
||
// Wrap the output of Magnolia in a Derived to force it to a lower priority. | ||
// This seems to work, despite magnolia hardcode checks for `macroApplication` symbol | ||
// and relying on getting an diverging implicit expansion error for auto-mode. | ||
// Thankfully at least it doesn't check the output type of its `macroApplication` | ||
def derivedMagnolia[TC[_], A: c.WeakTypeTag](c: whitebox.Context): c.Expr[Derived[TC[A]]] = { | ||
val magnoliaTree = c.Expr[TC[A]](Magnolia.gen[A](c)) | ||
c.universe.reify(Derived(magnoliaTree.splice)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters