This file contains 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 akka.actor.ActorSystem | |
import akka.stream.ActorFlowMaterializer | |
import akka.http.scaladsl.model.headers._ | |
import akka.http.scaladsl.Http | |
import akka.http.scaladsl.server._ | |
import akka.http.scaladsl.model.StatusCodes._ | |
import akka.http.scaladsl.server.Directives._ | |
object OptionsMethod extends App { |
This file contains 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 scala.reflect.runtime.universe.TypeTag | |
import scala.annotation.implicitNotFound | |
@implicitNotFound("Sorry, type inference was unable to figure out the type. You need to provide it explicitly.") | |
trait NotNothing[T] | |
object NotNothing { | |
private val evidence: NotNothing[Any] = new Object with NotNothing[Any] | |
implicit def notNothingEvidence[T](implicit n: T =:= T): NotNothing[T] = |
This file contains 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 object DateCoercionViolation extends ValueCoercionViolation("Date value expected") | |
def parseDate(s: String) = Try(new DateTime(s, DateTimeZone.UTC)) match { | |
case Success(date) => Right(date) | |
case Failure(_) => Left(DateCoercionViolation) | |
} | |
val DateTimeType = ScalarType[DateTime]("DateTime", | |
coerceOutput = date => ast.StringValue(ISODateTimeFormat.dateTime().print(date)), | |
coerceUserInput = { |
This file contains 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 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.marshalling.MarshallingUtil._ | |
import sangria.marshalling.circe._ | |
val marchaller: ResultMarshaller = ??? // provided in ExceptionHandler | |
val json: Json = ??? // your custom json | |
implicit val mForType = SimpleResultMarshallerForType[marchaller.Node](marchaller) | |
val converted: marchaller.Node = json.convertMarshaled[marchaller.Node] |
This file contains 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
$(function (global) { | |
/** | |
* This GraphiQL example illustrates how to use some of GraphiQL's props | |
* in order to enable reading and updating the URL parameters, making | |
* link sharing of queries a little bit easier. | |
* | |
* This is only one example of this kind of feature, GraphiQL exposes | |
* various React params to enable interesting integrations. | |
*/ | |
var graphiql = null |
This file contains 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
// For build.sbt: | |
// | |
// libraryDependencies ++= Seq( | |
// "io.circe" %% "circe-core" % "0.9.2", | |
// "io.circe" %% "circe-parser" % "0.9.2", | |
// "com.jayway.jsonpath" % "json-path" % "2.3.0") | |
import com.jayway.jsonpath.{InvalidJsonException, JsonPathException, Configuration, JsonPath, TypeRef} | |
import com.jayway.jsonpath.spi.json.JsonProvider | |
import com.jayway.jsonpath.spi.mapper.MappingProvider |
This file contains 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.ast.AstVisitor | |
import sangria.schema._ | |
import sangria.renderer.{QueryRenderer, QueryRendererConfig, SchemaFilter} | |
import sangria.visitor.VisitorCommand | |
def renderSchemaWithLegacyDescriptions(schema: Schema[_, _], filter: SchemaFilter = SchemaFilter.withoutSangriaBuiltIn, config: QueryRendererConfig = QueryRenderer.Pretty) = { | |
def commentDescription(node: ast.WithDescription) = | |
node.description.toVector.flatMap(sv ⇒ sv.value.split("\\r?\\n").toVector.map(ast.Comment(_))) |
This file contains 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 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, _, _]) = () |