This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sangria.ast._ | |
import sangria.execution._ | |
import sangria.schema.Context | |
import sangria.marshalling.queryAst._ | |
import java.util.concurrent.ConcurrentLinkedQueue | |
import scala.concurrent.duration.FiniteDuration | |
import scala.collection.JavaConverters._ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val UUIDType = ScalarAlias[UUID, String](StringType, | |
toScalar = _.toString, | |
fromScalar = idString ⇒ try Right(UUID.fromString(idString)) catch { | |
case _: IllegalArgumentException ⇒ Left(IDViolation) | |
}) | |
case object IDViolation extends ValueCoercionViolation("Invalid ID") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.Instant | |
import java.time.format.DateTimeFormatter | |
import java.util.concurrent.ConcurrentLinkedQueue | |
import sangria.ast._ | |
import sangria.execution._ | |
import sangria.schema.Context | |
import sangria.marshalling.queryAst._ | |
import sangria.renderer.SchemaRenderer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FieldMetrics(reporter: MetricsReporter) | |
extends Middleware[Any] | |
with MiddlewareAfterField[Any] | |
with MiddlewareErrorField[Any] { | |
type QueryVal = () | |
type FieldVal = Long | |
def beforeQuery(context: MiddlewareQueryContext[Any, _, _]) = () | |
def afterQuery(queryVal: QueryVal, context: MiddlewareQueryContext[Any, _, _]) = () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"data": { | |
"human": { | |
"name": "Luke Skywalker", | |
"appearsIn": ["NEWHOPE", "EMPIRE", "JEDI"], | |
"friends": [ | |
{"name": "Han Solo"}, | |
{"name": "Leia Organa"}, | |
{"name": "C-3PO"}, | |
{"name": "R2-D2"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [Execution Metrics] duration: 1424ms, validation: 1ms, reducers: 0ms | |
{ | |
# [Query] count: 1, time: 0ms | |
human(id: "1000") { | |
# [Human] count: 1, time: 0ms | |
name | |
# [Human] count: 1, time: 609ms | |
friends { | |
...Stuff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [Execution Metrics] duration: 12362ms, validation: 0ms, reducers: 0ms | |
# | |
# $id = "1000" | |
query Test($id: String!) { | |
# [Query] count: 1, time: 2ms | |
# | |
# $id = "1000" | |
human(id: $id) { | |
# [Human] count: 1, time: 0ms | |
name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Args { | |
val empty = new Args(Map.empty, Set.empty, Set.empty, Set.empty, TrieMap.empty) | |
def apply(definitions: List[Argument[_]], values: (String, Any)*): Args = | |
apply(definitions, values.toMap) | |
def apply(definitions: List[Argument[_]], values: Map[String, Any]): Args = | |
apply(definitions, input = ScalaInput.scalaInput(values)) | |
def apply[In: InputUnmarshaller](definitions: List[Argument[_]], input: In): Args = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class LoadCategories(ids: Seq[String]) extends Deferred[Seq[String]] | |
lazy val CategoryType: ObjectType[Unit, String] = ObjectType("Category", () ⇒ fields[Unit, String]( | |
Field("name", StringType, resolve = c ⇒ s"Cat ${c.value}"), | |
Field("children", ListType(CategoryType), | |
arguments = Argument("count", IntType) :: Nil, | |
resolve = c ⇒ LoadCategories((1 to c.arg[Int]("count")).map(i ⇒ s"${c.value}.$i"))) | |
)) | |
val QueryType = ObjectType("Query", fields[Unit, Unit]( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sangria.ast | |
import sangria.execution.Executor | |
import sangria.marshalling.{InputUnmarshaller, ScalarValueInfo, ArrayMapBuilder, ResultMarshaller} | |
import sangria.schema._ | |
import sangria.validation.{ValueCoercionViolation, IntCoercionViolation, BigIntCoercionViolation} | |
import spray.json._ | |
import sangria.macros._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
implicit object CustomSprayJsonResultMarshaller extends ResultMarshaller { |