All Projects → OlegIlyenko → sangria-http4s-graalvm-example

OlegIlyenko / sangria-http4s-graalvm-example

Licence: other
An example of GraphQL server built with sangria, http4s and circe which compiles and runs as a GraalVM native image.

Programming Languages

scala
5932 projects
HTML
75241 projects

An example of GraphQL server built with sangria, http4s and circe which compiles and runs as a GraalVM native image.

Prerequisites

Info

The creation of the native image is done entirely with sbt. The only requirement is docker. In order to make it possible to build a native image in any environment, I created this docker container which is used by the sbt build:

tenshi/graalvm-native-image

All packaging logic can be found in the packaging.sbt, including 2 sbt tasks: nativeImage and nativeImageDocker.

In order to compile a native image, just run:

sbt nativeImage 

It will create an image in target/native-image/sangria-http4s-graalvm-example.

If you would like to also create a local docker container with this application image, just run:

sbt nativeImageDocker

it will create a local docker container which you can run like this:

docker run -it --rm -p 8080:8080 sangria-http4s-graalvm-example server

The scala application itself has a following usage:

Usage: sangria-http4s-graalvm-example command [arguments..]

Following commands are available:

  server                Start the GraphQL server
  query <GRAPHQL_QUERY> Execute provided query and exit

So you can experiment with both: a CLI tool and http4s-based server.

When server is started, GraphiQL is available under http://localhost:8080 and the GraphQL endpoint itself is available under http://localhost:8080/graphql.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].