
sangria.execution.middleware.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sangria_2.11 Show documentation
Show all versions of sangria_2.11 Show documentation
Scala GraphQL implementation
package sangria.execution
import sangria.marshalling.InputUnmarshaller
import language.{implicitConversions, existentials}
import sangria.ast
import sangria.schema.{Action, Context}
trait Middleware[-Ctx] {
type QueryVal
def beforeQuery(context: MiddlewareQueryContext[Ctx, _, _]): QueryVal
def afterQuery(queryVal: QueryVal, context: MiddlewareQueryContext[Ctx, _, _]): Unit
}
trait MiddlewareBeforeField[Ctx] extends Middleware[Ctx] {
type FieldVal
def beforeField(queryVal: QueryVal, mctx: MiddlewareQueryContext[Ctx, _, _], ctx: Context[Ctx, _]): (FieldVal, Option[Action[Ctx, _]])
lazy val continue: (Unit, Option[Action[Ctx, _]]) = (Unit, None)
def continue(fieldVal: FieldVal): (FieldVal, Option[Action[Ctx, _]]) = (fieldVal, None)
}
trait MiddlewareAfterField[Ctx] extends MiddlewareBeforeField[Ctx] {
def afterField(queryVal: QueryVal, fieldVal: FieldVal, value: Any, mctx: MiddlewareQueryContext[Ctx, _, _], ctx: Context[Ctx, _]): Option[Any]
}
trait MiddlewareErrorField[Ctx] extends MiddlewareBeforeField[Ctx] {
def fieldError(queryVal: QueryVal, fieldVal: FieldVal, error: Throwable, mctx: MiddlewareQueryContext[Ctx, _, _], ctx: Context[Ctx, _]): Unit
}
case class MiddlewareQueryContext[+Ctx, RootVal, Input](
ctx: Ctx,
executor: Executor[_ <: Ctx, RootVal],
queryAst: ast.Document,
operationName: Option[String],
variables: Input,
inputUnmarshaller: InputUnmarshaller[Input])
trait FieldTag
case class StringTag(name: String)
object FieldTag {
implicit def stringTag(s: String): StringTag = StringTag(s)
implicit def symbolTag(s: Symbol): StringTag = StringTag(s.name)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy