Release Notes
This release brings a few important changes, including a refactor of request interceptors, support for the @defer
directive and support for Scala Native in caliban-client 🚀
Love this project? I am now on Github Sponsors. A good way to give back and encourage future developments! ❤️
New Adapter API
Request interceptors and configuration options such as skipValidation
or enableIntrospection
have been modified to be more powerful: you can now eliminate part of ZIO environment with request interceptors, and you can modify execution configuration dynamically.
These improvements require a small change in existing code. When calling makeHttpService
, makeHttpUploadService
or makeWebSocketService
, you now need to wrap your interpreter into (respectively) an HttpInterpreter
, HttpUploadInterpreter
or WebSocketInterpreter
.
// before
ZHttpAdapter.makeHttpService(interpreter)
// after
ZHttpAdapter.makeHttpService(HttpInterpreter(interpreter))
With these wrapper classes come 2 powerful methods:
configure
takes aConfigurator[R]
which is an alias forURIO[R & Scope, Unit]
.
It allows configuring the interpreter by running an effect that will run for each request and that can modify the configuration of the running fiber. Built-in configurators such assetSkipValidation
,setEnableIntrospection
andsetQueryExecution
are available in theConfigurator
object and let you dynamically change the configuration of the interpreter.intercept
takes anInterceptor[-R1, +R]
which is an alias forZLayer[R1 & ServerRequest, TapirResponse, R]
.
It is basically a more powerful version ofconfigure
that gives you access to the incoming request (ServerRequest
) and lets you modify the environment of the interpreter (fromR
toR1
). A typical use case would be to extract an authentication token from the request and eliminate the authentication requirement from the environment if the token is valid. See an example here. You can also use this to change the configuration based on the incoming request (e.g. allow introspection only when a valid token is present).
val interpreter: GraphQLInterpreter[AuthToken, CalibanError] = ???
// turn our GraphQL interpreter into an HttpInterpreter
val noAuthInterpreter: HttpInterpreter[AuthToken, CalibanError] = HttpInterpreter(interpreter)
// define authentication logic (from a ServerRequest, fail or build an AuthToken)
val auth: ZLayer[ServerRequest, TapirResponse, AuthToken] = ???
// pass our interceptor to eliminate the AuthToken requirement from the environment
val authInterpreter: HttpUploadInterpreter[Any, CalibanError] = httpInterpreter.intercept(auth)
// get our route for Akka Http
val route = AkkaHttpAdapter.makeHttpService(authInterpreter)
This change was done in #1707 by @ghostdogpr
Other changes
Server
- Added experimental support for the
@defer
directive #1480 by @paulpdaniels - Added directives parameter to
scalarSchema
#1694 by @yarian - Added support for
derives ArgBuilder.GenAuto
derivation #1699 by @kyri-petrou - Added support for adding directives to individual enums #1663 by @paulpdaniels
- Fixed
derives Schema.Auto
derivation #1666 by @kyri-petrou - Fixed rendering of directives in arguments #1690 by @tusharmath
- Fixed repeatable directive introspection #1695 by @ghostdogpr
- Fixed propogation of directives in
objectSchema
#1698 by @yarian
Client
- Added support for Scala Native #1682 by @kyri-petrou