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

🎉 sangria-akka-http -> sangria-http & subprojects #12

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: sbt --client '++${{ matrix.scala }}; test'

- name: Compress target directories
run: tar cf targets.tar target core/target circe/target project/target
run: tar cf targets.tar target core/target akka/target akka-circe/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
Expand Down
9 changes: 5 additions & 4 deletions circe/build.sbt → akka-circe/build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import Dependencies._

name := "sangria-akka-http-circe"
name := "sangria-http-akka-circe"
organization := "org.sangria-graphql"

libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"de.heikoseeberger" %% "akka-http-circe" % "1.36.0",
"de.heikoseeberger" %% "akka-http-circe" % "1.37.0",
"org.sangria-graphql" %% "sangria-circe" % SangriaVersion.sangriaCirce,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion % Test,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion % Test,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test,
"io.circe" %% "circe-optics" % circeVersion % Test
"io.circe" %% "circe-optics" % circeVersion % Test,
"org.scalatest" %% "scalatest" % "3.2.9" % Test
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport
import io.circe._
import io.circe.generic.semiauto._
import sangria.execution.Executor
import sangria.http.akka.SangriaAkkaHttp.{GraphQLErrorResponse, MalformedRequest}
import sangria.http.akka.{GraphQLHttpRequest, SangriaAkkaHttp, Variables}
import sangria.http.{GraphQLHttpRequest, Variables}
import sangria.parser.SyntaxError
import sangria.schema.Schema

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package sangria.http.akka
package sangria.http.akka.circe

import akka.http.scaladsl.model.StatusCodes.{BadRequest, UnprocessableEntity}
import io.circe.Json
import org.scalatest.flatspec.AnyFlatSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sangria.http.akka
package sangria.http.akka.circe

import akka.http.scaladsl.model.StatusCodes._
import akka.http.scaladsl.server.Directives._
Expand All @@ -8,8 +8,7 @@ import org.scalatest.{Assertion, Suite}
import org.scalatest.flatspec.AnyFlatSpec
import io.circe.Json
import sangria.parser.SyntaxError
import sangria.http.akka.SangriaAkkaHttp._
import sangria.http.akka.circe.CirceHttpSupport
import SangriaAkkaHttp._

import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sangria.http.akka
package sangria.http.akka.circe

import java.net.URLEncoder
import java.nio.charset.StandardCharsets
Expand Down
10 changes: 10 additions & 0 deletions akka/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Dependencies._

name := "sangria-http-akka"
organization := "org.sangria-graphql"

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion % Test,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package sangria.http.akka

import java.nio.charset.StandardCharsets
package sangria.http.akka.circe

import akka.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import akka.http.scaladsl.model._
Expand All @@ -10,6 +8,7 @@ import sangria.ast.Document
import sangria.parser.QueryParser
import sangria.renderer.{QueryRenderer, QueryRendererConfig}

import java.nio.charset.StandardCharsets
import scala.collection.immutable.Seq

object GraphQLRequestUnmarshaller {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
package sangria.http.akka
package sangria.http.akka.circe

import akka.http.javadsl.server.RequestEntityExpectedRejection
import akka.http.scaladsl.marshalling.ToEntityMarshaller
import akka.http.scaladsl.model.MediaTypes._
import akka.http.scaladsl.model.StatusCodes.{BadRequest, InternalServerError, UnprocessableEntity}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.{
Directive,
ExceptionHandler,
MalformedQueryParamRejection,
MalformedRequestContentRejection,
RejectionHandler,
Route,
StandardRoute
}
import akka.http.scaladsl.server._
import akka.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, FromStringUnmarshaller}
import Util.explicitlyAccepts
import sangria.ast.Document
import sangria.parser.{QueryParser, SyntaxError}
import GraphQLRequestUnmarshaller._
import akka.http.javadsl.server.RequestEntityExpectedRejection
import akka.http.scaladsl.marshalling.ToEntityMarshaller
import akka.http.scaladsl.model.StatusCodes.{
BadRequest,
InternalServerError,
OK,
UnprocessableEntity
}
import Util.explicitlyAccepts
import sangria.http.{GraphQLHttpRequest, PreparedGraphQLRequest, Variables}
import sangria.parser.{QueryParser, SyntaxError}

import scala.util.control.NonFatal
import scala.util.{Failure, Success, Try}

trait SangriaAkkaHttp[Input] {
import SangriaAkkaHttp._

type GQLRequestHandler = PartialFunction[Try[GraphQLRequest[Input]], StandardRoute]
type GQLRequestHandler = PartialFunction[Try[PreparedGraphQLRequest[Input]], StandardRoute]
implicit def errorMarshaller: ToEntityMarshaller[GraphQLErrorResponse]
implicit def requestUnmarshaller: FromEntityUnmarshaller[GraphQLHttpRequest[Input]]
implicit def variablesUnmarshaller: FromStringUnmarshaller[Input]
Expand Down Expand Up @@ -129,7 +117,7 @@ trait SangriaAkkaHttp[Input] {

prepareQuery(maybeQuery) match {
case Success(document) =>
val result = GraphQLRequest(
val result = PreparedGraphQLRequest(
query = document,
variables = maybeVariables,
operationName = maybeOperationName
Expand All @@ -140,7 +128,7 @@ trait SangriaAkkaHttp[Input] {
} ~
// Content-Type: application/graphql
entity(as[Document]) { document =>
val result = GraphQLRequest(
val result = PreparedGraphQLRequest(
query = document,
variables = variablesParam,
operationName = operationNameParam)
Expand All @@ -152,7 +140,7 @@ trait SangriaAkkaHttp[Input] {
extractParams { (maybeQuery, maybeOperationName, maybeVariables) =>
prepareQuery(maybeQuery) match {
case Success(document) =>
val result = GraphQLRequest(
val result = PreparedGraphQLRequest(
query = document,
variables = maybeVariables,
maybeOperationName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sangria.http.akka
package sangria.http.akka.circe

import akka.http.scaladsl.model.MediaType
import akka.http.scaladsl.model.headers.Accept
Expand Down
7 changes: 0 additions & 7 deletions app.json

This file was deleted.

16 changes: 10 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ThisBuild / name := "sangria-akka-http"
ThisBuild / name := "sangria-http"
ThisBuild / organization := "org.sangria-graphql"

ThisBuild / description := "Sangria Akka HTTP Support"
ThisBuild / description := "Sangria HTTP Support"
ThisBuild / homepage := Some(url("https://sangria-graphql.github.io/"))
ThisBuild / licenses := Seq(
"Apache License, ASL Version 2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0"))
Expand Down Expand Up @@ -38,13 +38,17 @@ ThisBuild / githubWorkflowPublish := Seq(
)

lazy val core = project in file("core")

lazy val circe = (project in file("circe"))
lazy val akka = (project in file("akka"))
.dependsOn(core % "test->test;compile->compile")
lazy val akkaCirce = (project in file("akka-circe"))
.dependsOn(
core % "test->test;compile->compile",
akka % "test->test;compile->compile"
)

lazy val root = (project in file("."))
.aggregate(core, circe)
.aggregate(core, akka, akkaCirce)
.settings(
name := "sangria-akka-http",
name := "sangria-http",
publishArtifact := false
)
7 changes: 1 addition & 6 deletions core/build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import Dependencies._

name := "sangria-akka-http-core"
name := "sangria-http"
organization := "org.sangria-graphql"

libraryDependencies ++= Seq(
"org.sangria-graphql" %% "sangria" % SangriaVersion.sangria,
"org.sangria-graphql" %% "sangria-slowlog" % SangriaVersion.sangriaSlowlog,
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"org.scalatest" %% "scalatest" % "3.2.9" % Test
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sangria.http.akka
package sangria.http

case class GraphQLHttpRequest[T](
query: Option[String],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package sangria.http.akka
package sangria.http

import sangria.ast.Document

case class GraphQLRequest[T](query: Document, variables: T, operationName: Option[String])
case class PreparedGraphQLRequest[T](query: Document, variables: T, operationName: Option[String])

object GraphQLRequest {
object PreparedGraphQLRequest {
def apply[T](query: Document, variables: Option[T], operationName: Option[String])(implicit
v: Variables[T]): GraphQLRequest[T] =
new GraphQLRequest(
v: Variables[T]): PreparedGraphQLRequest[T] =
new PreparedGraphQLRequest(
query = query,
variables = variables.fold(v.empty)(identity),
operationName = operationName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sangria.http.akka
package sangria.http

trait Variables[T] {
def empty: T
Expand Down