Conversation
This reverts commit 7c28acb.
|
I found a new approach that supports the ZIO environment and using arbitrary Kyo effects 🎉 |
fwbrasil
left a comment
There was a problem hiding this comment.
LGTM! Thank you for working on this @ghostdogpr, it'll be quite useful :)
| object Resolvers: | ||
|
|
||
| private given StreamConstructor[Nothing] = | ||
| (_: ZStream[Any, Throwable, Byte]) => throw new Throwable("Streaming is not supported") |
There was a problem hiding this comment.
Will this work? compiletime.error("Streaming is not yet supported.")
There was a problem hiding this comment.
I think it'd require inline given as well
There was a problem hiding this comment.
But we don't want a compile error here, we need to provide a StreamConstructor for NoStreams, which is the only stream implementation we can use now. Once streaming is supported by NettyKyoServer, this can be removed.
| def run[R, T, S](server: NettyKyoServer, runner: Runner[R])(v: HttpInterpreter[Runner[R], CalibanError] < (Resolvers & S))(using | ||
| tag: Tag[Runner[R]] | ||
| ): NettyKyoServerBinding < (ZIOs & Aborts[CalibanError] & S) = | ||
| ZIOs.get(ZIO.runtime[Any]).map(runtime => run(server, runtime.withEnvironment(ZEnvironment(runner)))(v)) |
| def run[R, T, S](runner: Runner[R])(v: HttpInterpreter[Runner[R], CalibanError] < (Resolvers & S))(using | ||
| tag: Tag[Runner[R]] | ||
| ): NettyKyoServerBinding < (ZIOs & Aborts[CalibanError] & S) = | ||
| run[R, T, S](NettyKyoServer(), runner)(v) |
There was a problem hiding this comment.
Perhaps we should provide the NettyKyoServer() with a Locals?
There was a problem hiding this comment.
I did the same thing as in the existing Routes effect.
| import sttp.tapir.capabilities.NoStreams | ||
| import sttp.tapir.server.ServerEndpoint | ||
| import sttp.tapir.server.netty.* | ||
| import zio.* |
There was a problem hiding this comment.
How many places do you use ZIO? It might be good to only import the types you use due to probability of collisions, eg: Tags
| runtime: Runtime[R] | ||
| ): ServerEndpoint[Any, KyoSttpMonad.M] = | ||
| ServerEndpoint[Unit, Unit, I, TapirResponse, CalibanResponse[NoStreams.BinaryStream], Any, KyoSttpMonad.M]( | ||
| endpoint.endpoint.asInstanceOf[Endpoint[Unit, I, TapirResponse, CalibanResponse[NoStreams.BinaryStream], Any]], |
There was a problem hiding this comment.
Is there a way to avoid casting?
There was a problem hiding this comment.
I couldn't find a way. The problem is with the last type parameter, R which should be Any. But we're using NoStreams because Caliban does require a Stream implementation and it's the only one we can use for now. The cast can also be removed once streams are supported in NettyKyoServer.
| ): ServerEndpoint[Any, KyoSttpMonad.M] = | ||
| ServerEndpoint[Unit, Unit, I, TapirResponse, CalibanResponse[NoStreams.BinaryStream], Any, KyoSttpMonad.M]( | ||
| endpoint.endpoint.asInstanceOf[Endpoint[Unit, I, TapirResponse, CalibanResponse[NoStreams.BinaryStream], Any]], | ||
| _ => _ => Right(()), |
There was a problem hiding this comment.
If this will be invoked more than once, let's create a rightUnit constant.
There was a problem hiding this comment.
Good point, done!
| "arbitrary kyo effects" in runZIO { | ||
| type Env = Vars[Int] & Envs[String] |
|
Documentation added! I'll create the additional issue for Streaming/WebSocket support after this is merged. |
README.md
Outdated
| // for other effects, you need to extend `SchemaDerivation[Runner[YourEnv]]` | ||
| type Env = Vars[Int] & Envs[String] |
There was a problem hiding this comment.
I would prefer not to overload the term Env - potentially confusing with Envs[A] or ZIO's R (which is often type aliased to Env....
Can we use Effects? or Pending?
There was a problem hiding this comment.
Changed to CustomEffects
README.md
Outdated
| `Resolvers` integrates with the [Caliban](https://github.com/ghostdogpr/caliban) library to help setup GraphQL servers. | ||
|
|
||
| The first integration is that you can use Kyo effects inside your Caliban schemas. | ||
| - If your Kyo effects is `(Aborts[Throwable] & ZIOs)` or a subtype of it, a Caliban `Schema` can be derived automatically. |
There was a problem hiding this comment.
Might be worth noting that ZIOs includes Fibers/IOs.
|
I'm happy to see this merged!!!! Thanks folks!!!! |
/fixes #216
/claim #216
Schema derivation
You can now use kyo effects in your resolvers and schemas are derived with 2 different givens:
(Aborts[Throwable] & ZIOs), it works out of the boxSchemaDerivation[Runner[S]]to derive the schema, and you will need to provide theRunneronrunResolvers effect
Resolvers.run { Resolvers.get(api) }to simply turn a calibanGraphQLapi into a running serverResolvers.run(runner) { Resolvers.get(api) }NettyKyoServerand a ZIORuntimeNote that
Resolvers.getreturns Caliban'sHttpInterpreterwhich allows customizing configuration, adding middleware, changing the endpoints (e.g. path), etcFurther work