Skip to content

Commit

Permalink
prepare for custom resolver
Browse files Browse the repository at this point in the history
move current Resolver into FutureResolver
make more private methods to mroe easily adapt the behavior
  • Loading branch information
yanns committed Mar 31, 2023
1 parent 5860045 commit e7576c1
Show file tree
Hide file tree
Showing 5 changed files with 2,006 additions and 1,823 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ 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
val resolverBuilder: ResolverBuilder
}

object ExecutionScheme extends AlternativeExecutionScheme {
Expand All @@ -34,6 +35,8 @@ object ExecutionScheme extends AlternativeExecutionScheme {
future.flatMap(resultFn)

def extended = false

override val resolverBuilder: ResolverBuilder = FutureResolverBuilder
}
}

Expand All @@ -46,7 +49,8 @@ trait EffectOps[F[_]] {

@ApiMayChange
class EffectBasedExecutionScheme[F[_]](
ops: EffectOps[F]
val ops: EffectOps[F],
val resolverBuilder: ResolverBuilder
) extends ExecutionScheme {
override type Result[Ctx, Res] = F[Res]
override def failed[Ctx, Res](error: Throwable): Result[Ctx, Res] =
Expand Down Expand Up @@ -85,6 +89,8 @@ trait AlternativeExecutionScheme {
future.flatMap(resultFn)

def extended = true

override val resolverBuilder: ResolverBuilder = FutureResolverBuilder
}

implicit def Stream[S[_]](implicit
Expand All @@ -107,6 +113,8 @@ trait AlternativeExecutionScheme {
def flatMapFuture[Ctx, Res, T](future: Future[T])(resultFn: T => Result[Ctx, Res])(implicit
ec: ExecutionContext): Result[Ctx, Res] =
stream.flatMapFuture(future)(resultFn)

override val resolverBuilder: ResolverBuilder = FutureResolverBuilder
}

implicit def StreamExtended[S[_]](implicit
Expand All @@ -129,6 +137,8 @@ trait AlternativeExecutionScheme {
def flatMapFuture[Ctx, Res, T](future: Future[T])(resultFn: T => Result[Ctx, Res])(implicit
ec: ExecutionContext): Result[Ctx, Res] =
stream.flatMapFuture(future)(resultFn)

override val resolverBuilder: ResolverBuilder = FutureResolverBuilder
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ case class Executor[Ctx, Root](
val middlewareVal = middleware.map(m => m.beforeQuery(middlewareCtx) -> m)
val deferredResolverState = deferredResolver.initialQueryState

val resolver = new Resolver[Ctx](
val resolver = scheme.resolverBuilder.build[Ctx](
marshaller,
middlewareCtx,
schema,
Expand Down
Loading

0 comments on commit e7576c1

Please sign in to comment.