Skip to content

Commit

Permalink
Allow to hide unsafe call with akka-http wrapper
Browse files Browse the repository at this point in the history
rename to makeHttpServiceM

fmt
  • Loading branch information
loicdescotte committed Jan 28, 2020
1 parent 958fc10 commit a67ea13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 5 additions & 0 deletions akka-http/src/main/scala/caliban/AkkaHttpAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ object AkkaHttpAdapter extends FailFastCirceSupport {
.future
)

def makeHttpServiceM[R, E](
interpreter: URIO[R, GraphQLInterpreter[R, E]]
)(implicit ec: ExecutionContext, runtime: Runtime[R]): Route =
makeHttpService(runtime.unsafeRun(interpreter))

def makeHttpService[R, E](
interpreter: GraphQLInterpreter[R, E]
)(implicit ec: ExecutionContext, runtime: Runtime[R]): Route = {
Expand Down
5 changes: 2 additions & 3 deletions examples/src/main/scala/caliban/akkahttp/ExampleApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object ExampleApp extends App with GenericSchema[Console with Clock] {
case class Mutations(deleteCharacter: CharacterArgs => URIO[Console, Boolean])
case class Subscriptions(characterDeleted: ZStream[Console, Nothing, String])

val interpreter = defaultRuntime.unsafeRun(
val interpreter =
ExampleService
.make(sampleCharacters)
.map(service => {
Expand All @@ -49,7 +49,6 @@ object ExampleApp extends App with GenericSchema[Console with Clock] {
)
).interpreter
})
)

/**
* curl -X POST \
Expand All @@ -62,7 +61,7 @@ object ExampleApp extends App with GenericSchema[Console with Clock] {
*/
val route =
path("api" / "graphql") {
AkkaHttpAdapter.makeHttpService(interpreter)
AkkaHttpAdapter.makeHttpServiceM(interpreter)
} ~ path("graphiql") {
getFromResource("graphiql.html")
}
Expand Down

0 comments on commit a67ea13

Please sign in to comment.