Skip to content

Instantly share code, notes, and snippets.

@duanebester
Last active November 14, 2019 01:59
Show Gist options
  • Save duanebester/40eb438a943b53a5e1108f3b05746f9a to your computer and use it in GitHub Desktop.
Save duanebester/40eb438a943b53a5e1108f3b05746f9a to your computer and use it in GitHub Desktop.
Main Scala App - 0
object Main extends App {
val PORT = 8080
implicit val actorSystem = ActorSystem("graphql-server")
implicit val materializer = ActorMaterializer()
import actorSystem.dispatcher
scala.sys.addShutdownHook(() -> shutdown())
val route: Route =
(post & path("graphql")) {
entity(as[JsValue]) { requestJson =>
complete("GraphQL")
}
} ~ {
getFromResource("graphiql.html")
}
Http().bindAndHandle(route, "0.0.0.0", PORT)
println(s"GraphiQL Available at: http://localhost:$PORT")
def shutdown(): Unit = {
actorSystem.terminate()
Await.result(actorSystem.whenTerminated, 30 seconds)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment