Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unsafeRunServer method #2050

Merged
merged 4 commits into from
Dec 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion adapters/quick/src/main/scala/caliban/quick/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package caliban

import caliban.Configurator.ExecutionConfiguration
import zio.http._
import zio.{ RIO, Trace, ZIO }
import zio.{ RIO, Trace, ZIO, ZIOAppDefault }

package object quick {

Expand Down Expand Up @@ -70,4 +70,20 @@ package object quick {
gql.interpreter.map(QuickAdapter(_).configure(config).handler)
}

implicit class GraphqlAnyServerOps[R](val gql: GraphQL[Any]) extends AnyVal {

/**
* Convenience method for impurely running the server.
*
* Useful for scripts / demos / showing off Caliban to your colleagues etc.
*/
def unsafeRunServer(
port: Int = 8080,
apiPath: String = "/graphql",
graphiqlPath: Option[String] = Some("/graphiql"),
uploadPath: Option[String] = None
)(implicit trace: Trace): Unit =
ZIOAppDefault(gql.runServer(port, apiPath, graphiqlPath, uploadPath)).main(Array.empty)
}

}