Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
yanns committed Mar 9, 2023
1 parent 427f640 commit 314edd3
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 103 deletions.
33 changes: 32 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,38 @@ lazy val core = project
ProblemFilters.exclude[IncompatibleMethTypeProblem](
"sangria.execution.Resolver.resolveSimpleListValue"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.schema.Field.subs"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.schema.Field.apply")
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.schema.Field.apply"),
ProblemFilters.exclude[ReversedMissingMethodProblem](
"sangria.execution.ExecutionScheme.effectScheme"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.execution.Resolver.handleScheme"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.execution.Resolver.this"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.processFinalResolve"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.execution.Resolver.resolveSeq"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.ParentDeferredContext"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.ErrorFieldResolution"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.StandardFieldResolution"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.StreamFieldResolution"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.execution.Resolver.resolveSubs"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.collectActionsPar"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.resolveActionsPar"),
ProblemFilters.exclude[DirectMissingMethodProblem]("sangria.execution.Resolver.resolveValue"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.resolveValue$default$7"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.isUndefinedValue"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.resolveSimpleListValue"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver.nullForNotNullTypeError"),
ProblemFilters.exclude[DirectMissingMethodProblem](
"sangria.execution.Resolver#Result.builderValue")
),
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oF"),
libraryDependencies ++= Seq(
Expand Down
28 changes: 28 additions & 0 deletions modules/core/src/main/scala/sangria/execution/EffectScheme.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sangria.execution

import scala.collection.BuildFrom
import scala.concurrent.{ExecutionContext, Future}

trait EffectScheme {
type F[_]
def map[A, B](eff: F[A])(f: A => B): F[B]
def flatMap[A, B](eff: F[A])(f: A => F[B]): F[B]
def success[A](a: A): F[A]
def sequence[A, CC[X] <: IterableOnce[X]](in: CC[F[A]])(implicit
bf: BuildFrom[CC[F[A]], A, CC[A]]): F[CC[A]]
def fromFuture[A](f: Future[A]): F[A]
def toFuture[A](f: F[A]): Future[A]
}

class FutureEffectScheme(implicit ec: ExecutionContext) extends EffectScheme {
override type F[A] = Future[A]

override def map[A, B](eff: Future[A])(f: A => B): Future[B] = eff.map(f)
override def flatMap[A, B](eff: Future[A])(f: A => Future[B]): Future[B] = eff.flatMap(f)
override def success[A](a: A): Future[A] = Future.successful(a)
def sequence[A, CC[X] <: IterableOnce[X]](in: CC[Future[A]])(implicit
bf: BuildFrom[CC[Future[A]], A, CC[A]]): Future[CC[A]] =
Future.sequence(in)
override def fromFuture[A](f: Future[A]): Future[A] = f
override def toFuture[A](f: Future[A]): Future[A] = f
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ sealed trait ExecutionScheme {
def flatMapFuture[Ctx, Res, T](future: Future[T])(resultFn: T => Result[Ctx, Res])(implicit
ec: ExecutionContext): Result[Ctx, Res]
def extended: Boolean
def effectScheme(ec: ExecutionContext): EffectScheme
}

object ExecutionScheme extends AlternativeExecutionScheme {
implicit object Default extends ExecutionScheme {
type Result[Ctx, Res] = Future[Res]

override def effectScheme(ec: ExecutionContext): EffectScheme = new FutureEffectScheme()(ec)

def failed[Ctx, Res](error: Throwable): Result[Ctx, Res] =
Future.failed(error)

Expand All @@ -46,19 +49,18 @@ trait EffectOps[F[_]] {

@ApiMayChange
class EffectBasedExecutionScheme[F[_]](
ops: EffectOps[F]
ops: EffectOps[F],
effect: EffectScheme
) extends ExecutionScheme {
override type Result[Ctx, Res] = F[Res]
override def effectScheme(ec: ExecutionContext): EffectScheme = effect
override def failed[Ctx, Res](error: Throwable): Result[Ctx, Res] =
ops.failed(error)
override def onComplete[Ctx, Res](result: Result[Ctx, Res])(op: => Unit)(implicit
ec: ExecutionContext): Result[Ctx, Res] = ???
override def flatMapFuture[Ctx, Res, T](future: Future[T])(resultFn: T => Result[Ctx, Res])(
implicit ec: ExecutionContext): Result[Ctx, Res] =
ops.flatMapFuture(future)(resultFn)
def mapEffect[Ctx, Res, T](future: Future[(Ctx, T)])(f: (Ctx, T) => Res)(implicit
ec: ExecutionContext): F[Res] =
ops.map(future) { case (ctx, in) => f(ctx, in) }

override def extended: Boolean = false
}
Expand All @@ -70,6 +72,7 @@ trait AlternativeExecutionScheme {

implicit object Extended extends ExecutionScheme {
type Result[Ctx, T] = Future[ExecutionResult[Ctx, T]]
override def effectScheme(ec: ExecutionContext): EffectScheme = new FutureEffectScheme()(ec)

def failed[Ctx, Res](error: Throwable): Result[Ctx, Res] =
Future.failed(error)
Expand All @@ -93,6 +96,7 @@ trait AlternativeExecutionScheme {
} =
new ExecutionScheme with StreamBasedExecutionScheme[S] {
type Result[Ctx, T] = S[T]
override def effectScheme(ec: ExecutionContext): EffectScheme = new FutureEffectScheme()(ec)

def subscriptionStream = stream
def extended = false
Expand All @@ -115,6 +119,7 @@ trait AlternativeExecutionScheme {
} =
new ExecutionScheme with StreamBasedExecutionScheme[S] {
type Result[Ctx, T] = S[ExecutionResult[Ctx, T]]
override def effectScheme(ec: ExecutionContext): EffectScheme = new FutureEffectScheme()(ec)

def subscriptionStream = stream
def extended = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ case class Executor[Ctx, Root](
validationTiming,
queryReducerTiming,
queryAst
)
)(executionContext, scheme.effectScheme(executionContext))

val result =
operation.operationType match {
Expand Down
Loading

0 comments on commit 314edd3

Please sign in to comment.