github ghostdogpr/caliban v1.3.0

latest releases: v2.9.0, v2.8.1, v2.8.0...
2 years ago

Release Notes

This release brings two important changes to Caliban:

  • the server adapters have been completely rewritten using Tapir
  • the Schema.gen function has been changed to make it easier to deal with ZIO environment, especially with Scala 3

New adapters based on Tapir

Adapters have been completely rewritten and are now sharing code thanks to Tapir, with the following benefits:

  • features are now consistent between each of the adapters: upload support, request interceptors, websocket hooks...
  • you can create your own adapter very easily for any library that Tapir supports
  • you can use the Json library of your choice easily
  • tapir endpoints can be used to generate an sttp client (our test suite takes advantage of that)

Notable changes:

  • FinchAdapter has been removed
  • PlayRouter has been removed, in favor of PlayAdapter which is consistent with the other adapters
  • AkkaHttpAdapter json support is now done via tapir
  • Http4sAdapter requires Clock with Blocking in the environment (this constraint comes from the tapir interpreter)
  • ContextWrapper is now RequestInterceptor
  • Callbacks is now WebSocketHooks

Look at the documentation for more info. Examples have been updated and migration shouldn't be difficult, but feel free to drop by Discord if you need any help.

Change done in #1125 by @ghostdogpr

New gen function

TL;DR
gen[A] becomes gen[R, A]

For Scala 2:
You no longer need to worry about calling the right gen (from Schema vs GenericSchema), you can simply use Schema.gen everywhere. It now takes 2 type parameters R and A but you can usually omit them if you explicitly define the return type of your schema.

object schema extends GenericSchema[MyEnv]
import schema._

implicit val queriesSchema: Schema[MyEnv, Queries] = Schema.gen
// or
implicit val queriesSchema = Schema.gen[MyEnv, Queries]

If you use genMacro, you still need to do it on GenericSchema.

For Scala 3:
It is no longer necessary to use GenericSchema[R]. You can simply use Schema.gen when you need to explicitly derive a schema. Caliban will be able to derive a Schema[R, A] directly from that.

If your R is not Any, you need to pass it to the graphQL function, unless you already have a Schema[R, Query] in scope:

val api = graphQL[MyEnv, Queries, Unit, Unit](RootResolver(queries))
// or
implicit val queriesSchema: Schema[MyEnv, Queries] = Schema.gen
val api = graphQL(RootResolver(queries))

If you want to see the code generated by the derivation, you can use Schema.genDebug instead. It will print the generated code to the console when compiling.

Change done in #1115 by @ghostdogpr

Other Changes

Server

Client

  • Code generation for interfaces was modified #1103 #1169 by @AlixBa. For each interface, 3 functions will be generated:
    • one with no suffix that takes a SelectionBuilder for each member implementing the interface
    • one suffixed with Option that takes an optional SelectionBuilder for each member implementing the interface, with default to None. That allows you not specifying a selection for every possible member.
    • one suffixed with Interface that takes a SelectionBuilder of the interface itself. This is useful if you want to select the common fields without having to provide a selection for each member.

Tools

Don't miss a new caliban release

NewReleases is sending notifications on new releases.