From eaed53c2062d84a630ff08375d336630649b4073 Mon Sep 17 00:00:00 2001 From: kyri-petrou <67301607+kyri-petrou@users.noreply.github.com> Date: Wed, 29 Nov 2023 07:49:23 +0100 Subject: [PATCH] Add `apply` method to Schema (#2023) * Add `apply` method to Schema * Add `apply` method to ArgBuilder --- core/src/main/scala-2/caliban/schema/SchemaDerivation.scala | 1 + core/src/main/scala-3/caliban/schema/SchemaDerivation.scala | 2 ++ core/src/main/scala/caliban/schema/ArgBuilder.scala | 2 ++ .../test/scala-3/caliban/schema/SchemaDerivesAutoSpec.scala | 4 ++-- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala b/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala index 6faa84c43a..1c8aa42f9f 100644 --- a/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala +++ b/core/src/main/scala-2/caliban/schema/SchemaDerivation.scala @@ -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. diff --git a/core/src/main/scala-3/caliban/schema/SchemaDerivation.scala b/core/src/main/scala-3/caliban/schema/SchemaDerivation.scala index ad29c4a84f..8e0a602050 100644 --- a/core/src/main/scala-3/caliban/schema/SchemaDerivation.scala +++ b/core/src/main/scala-3/caliban/schema/SchemaDerivation.scala @@ -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]) diff --git a/core/src/main/scala/caliban/schema/ArgBuilder.scala b/core/src/main/scala/caliban/schema/ArgBuilder.scala index 866a8317aa..7849df4ded 100644 --- a/core/src/main/scala/caliban/schema/ArgBuilder.scala +++ b/core/src/main/scala/caliban/schema/ArgBuilder.scala @@ -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 } diff --git a/core/src/test/scala-3/caliban/schema/SchemaDerivesAutoSpec.scala b/core/src/test/scala-3/caliban/schema/SchemaDerivesAutoSpec.scala index df3df71c9c..7475cfe8f7 100644 --- a/core/src/test/scala-3/caliban/schema/SchemaDerivesAutoSpec.scala +++ b/core/src/test/scala-3/caliban/schema/SchemaDerivesAutoSpec.scala @@ -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 @@ -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")) ) },