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 removedPlayRouter
has been removed, in favor ofPlayAdapter
which is consistent with the other adaptersAkkaHttpAdapter
json support is now done via tapirHttp4sAdapter
requiresClock with Blocking
in the environment (this constraint comes from the tapir interpreter)ContextWrapper
is nowRequestInterceptor
Callbacks
is nowWebSocketHooks
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
- A new spec for GraphQL was released in October 2021. Support for some new features have been added:
- custom scalar specification URLs #1171 by @ghostdogpr
__typename
is not valid at subscription root #1163 by @ghostdogpr
- Fixed
withAdditionalTypes
behavior #1170 #1175 #1176 #1177 by @frekw @ghostdogpr - Fixed upload support when dealing with nested fields #1167 by @frekw
- Fixed deprecated directive support on manually created fields #1168 by @frekw
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 optionalSelectionBuilder
for each member implementing the interface, with default toNone
. That allows you not specifying a selection for every possible member. - one suffixed with
Interface
that takes aSelectionBuilder
of the interface itself. This is useful if you want to select the common fields without having to provide a selection for each member.
- one with no suffix that takes a
Tools
- Made the source generator plugin support server-side code generation #1137 #1155 by @nikodemin @kubukoz
- Added support for multiple setting sets per file in
CalibanPlugin
#1156 by @kubukoz - Added
calibanVersion
setting toCalibanPlugin
#1165 by @kubukoz - Updated scalafmt and stopped using deprecated methods #1174 by @AlixBa