-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Scala 3-specific method for building custom schemas (#2211)
* Add Scala 3-specific method for building custom schemas * Fix scaladoc * PR comment * Rename customObj in scaladoc
- Loading branch information
1 parent
b88f156
commit fa51e3a
Showing
4 changed files
with
52 additions
and
11 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
core/src/main/scala-2/caliban/schema/SchemaVersionSpecific.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,3 @@ | ||
package caliban.schema | ||
|
||
trait SchemaVersionSpecific |
33 changes: 33 additions & 0 deletions
33
core/src/main/scala-3/caliban/schema/SchemaVersionSpecific.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,33 @@ | ||
package caliban.schema | ||
|
||
import caliban.introspection.adt.__Field | ||
import caliban.parsing.adt.Directive | ||
|
||
transparent trait SchemaVersionSpecific extends GenericSchema[Any] { | ||
|
||
/** | ||
* Scala 3 variant of the `obj` method which improves UX for creating custom object schemas. | ||
* | ||
* {{{ | ||
* case class Author(id: String, firstName: String, lastName: String) | ||
* | ||
* given Schema[Any, Author] = Schema.customObj("Author")( | ||
* field("id")(_.id), | ||
* field("fullName")(author => s"${author.firstName} ${author.lastName}"), | ||
* ) | ||
* }}} | ||
* | ||
* @see [[caliban.schema.GenericSchema.obj]] | ||
*/ | ||
def customObj[R1, V]( | ||
name: String, | ||
description: Option[String] = None, | ||
directives: List[Directive] = Nil | ||
)( | ||
fields: FieldAttributes ?=> (__Field, V => Step[R1])* | ||
): Schema[R1, V] = | ||
obj(name, description, directives) { case given FieldAttributes => | ||
fields.toList.map(identity) | ||
} | ||
|
||
} |
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