Skip to content

Commit

Permalink
Add apply method to Schema (#2023)
Browse files Browse the repository at this point in the history
* Add `apply` method to Schema

* Add `apply` method to ArgBuilder
  • Loading branch information
kyri-petrou authored Nov 29, 2023
1 parent a36f832 commit eaed53c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ trait CommonSchemaDerivation[R] {
}

trait SchemaDerivation[R] extends CommonSchemaDerivation[R] {
def apply[A](implicit ev: Schema[R, A]): Schema[R, A] = ev

/**
* Returns an instance of `Schema` for the given type T.
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/scala-3/caliban/schema/SchemaDerivation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ trait CommonSchemaDerivation {
}

trait SchemaDerivation[R] extends CommonSchemaDerivation {
inline def apply[A]: Schema[R, A] = summonInline[Schema[R, A]]

inline def gen[R, A]: Schema[R, A] = derived[R, A]

inline def genDebug[R, A]: Schema[R, A] = PrintDerived(derived[R, A])
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/scala/caliban/schema/ArgBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ trait ArgBuilder[T] { self =>
}

object ArgBuilder extends ArgBuilderInstances {
def apply[T](implicit ev: ArgBuilder[T]): ArgBuilder[T] = ev

object auto extends AutoArgBuilderDerivation
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object SchemaDerivesAutoSpec extends ZIOSpecDefault {
case class Queries(field: ZQuery[Clock, Nothing, Field]) derives MySchema.Auto

assert(
summon[Schema[Console & Clock, Queries]]
MySchema[Queries]
.toType_()
.fields(__DeprecatedArgs())
.toList
Expand Down Expand Up @@ -84,7 +84,7 @@ object SchemaDerivesAutoSpec extends ZIOSpecDefault {
}
case class B(a: List[Option[consoleSchema.A]]) derives consoleSchema.Auto

assert(Types.collectTypes(summon[Schema[Console, B]].toType_()).map(_.name.getOrElse("")))(
assert(Types.collectTypes(consoleSchema[B].toType_()).map(_.name.getOrElse("")))(
not(contains("SomeA")) && not(contains("OptionA")) && not(contains("None"))
)
},
Expand Down

0 comments on commit eaed53c

Please sign in to comment.