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

Add apply method to Schema #2023

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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