akka-http-graphql


License

License

MIT
Categories

Categories

Akka Container Microservices Reactive libraries
GroupId

GroupId

com.github.sebruck
ArtifactId

ArtifactId

akka-http-graphql_2.13
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

akka-http-graphql
akka-http-graphql
Project URL

Project URL

https://github.com/Sebruck/akka-http-graphql/
Project Organization

Project Organization

sebruck
Source Code Management

Source Code Management

https://github.com/Sebruck/akka-http-graphql/

Download akka-http-graphql_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.sebruck/akka-http-graphql_2.13/ -->
<dependency>
    <groupId>com.github.sebruck</groupId>
    <artifactId>akka-http-graphql_2.13</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.sebruck/akka-http-graphql_2.13/
implementation 'com.github.sebruck:akka-http-graphql_2.13:0.2.0'
// https://jarcasting.com/artifacts/com.github.sebruck/akka-http-graphql_2.13/
implementation ("com.github.sebruck:akka-http-graphql_2.13:0.2.0")
'com.github.sebruck:akka-http-graphql_2.13:jar:0.2.0'
<dependency org="com.github.sebruck" name="akka-http-graphql_2.13" rev="0.2.0">
  <artifact name="akka-http-graphql_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.sebruck', module='akka-http-graphql_2.13', version='0.2.0')
)
libraryDependencies += "com.github.sebruck" % "akka-http-graphql_2.13" % "0.2.0"
[com.github.sebruck/akka-http-graphql_2.13 "0.2.0"]

Dependencies

compile (10)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.1
com.typesafe.akka : akka-http_2.13 jar 10.1.11
de.heikoseeberger : akka-http-circe_2.13 jar 1.29.1
io.circe : circe-core_2.13 jar 0.12.3
io.circe : circe-generic_2.13 jar 0.12.3
io.circe : circe-parser_2.13 jar 0.12.3
io.circe : circe-optics_2.13 jar 0.12.0
org.sangria-graphql : sangria_2.13 jar 2.0.0-M1
org.sangria-graphql : sangria-circe_2.13 jar 1.3.0
org.sangria-graphql : sangria-slowlog_2.13 jar 2.0.0-M1

test (3)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.1.0
com.typesafe.akka : akka-http-testkit_2.13 jar 10.1.11
com.typesafe.akka : akka-stream-testkit_2.13 jar 2.6.1

Project Modules

There are no modules declared in this project.

Akka HTTP Sangria GraphQL circe = 💖

This library allows to easily create a Sangria GraphQL server based on Akka HTTP and circe.

Supported Scala Versions

The library is published for scala 2.12 and 2.13.

Features

  • executing GraphQL queries via GET & POST
  • Anti CORS measures:
    • Decline mutations via GET
    • POST requests accept only content types application/json and application/graphql
  • Serve playground.html (if configured) on GET with Accepts: text/html

Usage

Add the following dependency to your sbt project

"com.github.sebruck" %% "akka-http-graphql" % "0.2.0"
  import akka.actor.ActorSystem
  import akka.http.scaladsl.Http
  import akka.stream.ActorMaterializer
  import com.sebruck.akka.http.graphql.GraphEndpoint
  import sangria.execution.deferred.DeferredResolver
  import sangria.schema._

  import scala.concurrent.ExecutionContextExecutor
  import scala.util.{Failure, Success}

  implicit val actorSystem: ActorSystem     = ActorSystem()
  implicit val mat: ActorMaterializer       = ActorMaterializer()
  implicit val ec: ExecutionContextExecutor = actorSystem.dispatcher

  // Define Schema
  val Query = ObjectType(
    "Query",
    fields[Unit, Unit](
      Field("test", StringType, resolve = _ => "Hello!")
    )
  )

  val MySchema = Schema(Query)

  // Initialise Akka Http Endpoint
  val endpoint = GraphEndpoint(schema = MySchema,
                               context = (),
                               deferredResolver = DeferredResolver.empty,
                               graphQLPath = "graphql",
                               graphQLPlaygroundResourcePath = Some("playground.html"))

  // Start server
  Http().bindAndHandle(endpoint.route, "127.0.0.1", 8080).onComplete {
    case Success(binding) =>
      println(s"Bound to $binding")
    case Failure(exception) => throw exception
  }

If you have the GraphQL Playground in your resources directory, you can now open http://localhost:8080/graphql in your browser and play with your freshly created GraphQL API!

Contributing

Contributions are very welcome!

Versions

Version
0.2.0