🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

io.github.d-exclaimation:ahql_2.13

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io.github.d-exclaimation:ahql_2.13

Akka Http Query Library, a minimal GraphQL client and server exposing as a set of akka-http utilities

Source
mavenMaven
Version
0.2.4
Version published
Maintainers
1
Source

logo

ahql

Akka Http Query Library, minimal GraphQL client and server exposing as a set of akka-http utilities.

Setup

Latest Version: 0.2.4

"io.github.d-exclaimation" %% "ahql" % latestVersion

Usage/Examples

Server Example

Using a Server instance

object Main extends SprayJsonSupport {
  implicit val system: ActorSystem[Nothing] =
    ActorSystem(Behaviors.empty, "--")

  val gqlServer: Ahql.Server[Context, Unit] =
    Ahql.createServer[Context, Unit](schema, (),
      httpMethodStrategy = HttpMethodStrategy.queryOnlyGet
    )

  val route: Route = path("graphql") {
    optionalHeaderValueByName("Authorization") { auth =>
      val context = Context(auth)
      gqlServer.applyMiddleware(context)
    }
  }
}

Using a shorthand

object Main extends SprayJsonSupport {
  implicit val system: ActorSystem[Nothing] =
    ActorSystem(Behaviors.empty, "--")

  val route: Route = path("graphql") {
    optionalHeaderValueByName("Authorization") { auth =>
      val context = Context(auth)
      Ahql.applyMiddleware[Context, Unit](schema, context, (),
        httpMethodStrategy = HttpMethodStrategy.queryOnlyGet
      )
    }
  }
}

Both will gave out two endpoints

POST: ".../graphql"
GET: ".../graphql"
Client Example

Using a Client instance

object Main extends SprayJsonSupport {
  implicit val system: ActorSystem[Nothing] =
    ActorSystem(Behaviors.empty, "--")

  val gqlClient: Ahql.Client =
    Ahql.createClient("http://localhost:4000/graphql")

  val query: ast.Document =
    graphql"""
    query {
      someField {
        nested1
        nested2
      }
    }
  """

  val GqlResponse(data, errors) = gqlClient
    .fetch(query = query,
      headers = headers.Authorization("Bearer token") :: Nil
    )
  // data: Option[JsObject]
  // errors: Option[Vector[JsObject]]
}

Using a shorthand

object Main extends SprayJsonSupport {
  implicit val system: ActorSystem[Nothing] =
    ActorSystem(Behaviors.empty, "--")

  val query: ast.Document =
    graphql"""
    query {
      someField {
        nested1
        nested2
      }
    }
  """

  val GqlResponse(data, errors) = Ahql
    .fetch(
      endpoint = "http://localhost:4000/graphql",
      query = query,
      headers = headers.Authorization("Bearer token") :: Nil
    )
  // data: Option[JsObject]
  // errors: Option[Vector[JsObject]]
}

Feedback

If you have any feedback, feel free to reach out through the issues tab or through my Twitter @d_exclaimation.

FAQs

Package last updated on 08 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts