Skip to content

Commit

Permalink
remove input unmarshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanda Steinwedel committed Oct 12, 2023
1 parent ce82d3e commit acf8842
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sangria.ast
import sangria.ast.{Document, SourceMapper}
import sangria.catseffect.schema.AsyncValue
import sangria.execution.deferred.DeferredResolver
import sangria.marshalling.{InputUnmarshaller, ResultMarshaller}
import sangria.marshalling.ResultMarshaller
import sangria.schema._

import scala.concurrent.{ExecutionContext, Future}
Expand All @@ -19,7 +19,7 @@ trait AsyncToFuture[F[_]] {

private[execution] class AsyncResolverBuilder[F[_]: Async](asyncToFuture: AsyncToFuture[F])
extends ResolverBuilder {
override def build[Ctx, Input](
override def build[Ctx](
marshaller: ResultMarshaller,
middlewareCtx: MiddlewareQueryContext[Ctx, _, _],
schema: Schema[Ctx, _],
Expand All @@ -37,10 +37,8 @@ private[execution] class AsyncResolverBuilder[F[_]: Async](asyncToFuture: AsyncT
preserveOriginalErrors: Boolean,
validationTiming: TimeMeasurement,
queryReducerTiming: TimeMeasurement,
queryAst: Document)(implicit
executionContext: ExecutionContext,
iu: InputUnmarshaller[Input]): Resolver[Ctx] =
new AsyncResolver[Ctx, Input, F](
queryAst: Document)(implicit executionContext: ExecutionContext): Resolver[Ctx] =
new AsyncResolver[Ctx, F](
marshaller,
middlewareCtx,
schema,
Expand Down Expand Up @@ -68,7 +66,7 @@ private[execution] class AsyncResolverBuilder[F[_]: Async](asyncToFuture: AsyncT
* For now, it's using the [[FutureResolver]] under the hood. Later, we can update its
* implementation to avoid using any [[Future]].
*/
private[execution] class AsyncResolver[Ctx, Input, F[_]: Async](
private[execution] class AsyncResolver[Ctx, F[_]: Async](
val marshaller: ResultMarshaller,
middlewareCtx: MiddlewareQueryContext[Ctx, _, _],
schema: Schema[Ctx, _],
Expand All @@ -88,12 +86,12 @@ private[execution] class AsyncResolver[Ctx, Input, F[_]: Async](
queryReducerTiming: TimeMeasurement,
queryAst: ast.Document,
asyncToFuture: AsyncToFuture[F]
)(implicit executionContext: ExecutionContext, iu: InputUnmarshaller[Input])
)(implicit executionContext: ExecutionContext)
extends Resolver[Ctx] {

private val asyncF: Async[F] = Async[F]

private val delegate = new FutureResolver[Ctx, Input](
private val delegate = new FutureResolver[Ctx](
marshaller,
middlewareCtx,
schema,
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/main/scala/sangria/execution/Executor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ case class Executor[Ctx, Root](
val middlewareVal = middleware.map(m => m.beforeQuery(middlewareCtx) -> m)
val deferredResolverState = deferredResolver.initialQueryState

val resolver = scheme.resolverBuilder.build[Ctx, Input](
val resolver = scheme.resolverBuilder.build[Ctx](
marshaller,
middlewareCtx,
schema,
Expand All @@ -273,7 +273,7 @@ case class Executor[Ctx, Root](
validationTiming,
queryReducerTiming,
queryAst
)(executionContext, inputUnmarshaller)
)

val result =
operation.operationType match {
Expand Down
52 changes: 16 additions & 36 deletions modules/core/src/main/scala/sangria/execution/FutureResolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sangria.execution
import sangria.ast
import sangria.ast.{AstLocation, Document, SourceMapper}
import sangria.execution.deferred.{Deferred, DeferredResolver}
import sangria.marshalling.{InputUnmarshaller, ResultMarshaller}
import sangria.marshalling.ResultMarshaller
import sangria.schema._
import sangria.streaming.SubscriptionStream

Expand All @@ -15,7 +15,7 @@ import scala.util.control.NonFatal
import scala.util.{Failure, Success}

private[execution] object FutureResolverBuilder extends ResolverBuilder {
override def build[Ctx, Input](
override def build[Ctx](
marshaller: ResultMarshaller,
middlewareCtx: MiddlewareQueryContext[Ctx, _, _],
schema: Schema[Ctx, _],
Expand All @@ -33,12 +33,8 @@ private[execution] object FutureResolverBuilder extends ResolverBuilder {
preserveOriginalErrors: Boolean,
validationTiming: TimeMeasurement,
queryReducerTiming: TimeMeasurement,
queryAst: Document
)(implicit
executionContext: ExecutionContext,
iu: InputUnmarshaller[Input]
): Resolver[Ctx] =
new FutureResolver[Ctx, Input](
queryAst: Document)(implicit executionContext: ExecutionContext): Resolver[Ctx] =
new FutureResolver[Ctx](
marshaller,
middlewareCtx,
schema,
Expand All @@ -63,7 +59,7 @@ private[execution] object FutureResolverBuilder extends ResolverBuilder {
/** [[Resolver]] using [[scala.concurrent.Future]] and [[scala.concurrent.Promise]] as base
* asynchronous primitives
*/
private[execution] class FutureResolver[Ctx, Input](
private[execution] class FutureResolver[Ctx](
val marshaller: ResultMarshaller,
middlewareCtx: MiddlewareQueryContext[Ctx, _, _],
schema: Schema[Ctx, _],
Expand All @@ -82,7 +78,7 @@ private[execution] class FutureResolver[Ctx, Input](
validationTiming: TimeMeasurement,
queryReducerTiming: TimeMeasurement,
queryAst: ast.Document
)(implicit executionContext: ExecutionContext, iu: InputUnmarshaller[Input])
)(implicit executionContext: ExecutionContext)
extends Resolver[Ctx] {
private val resultResolver =
new ResultResolver(marshaller, exceptionHandler, preserveOriginalErrors)
Expand Down Expand Up @@ -1542,7 +1538,7 @@ private[execution] class FutureResolver[Ctx, Input](
private def trackDeprecation(ctx: Context[Ctx, _]): Unit = {
val visitedDirectives = mutable.Set[String]()

def getArgValue(name: String, args: Args): Option[Input] =
def getArgValue(name: String, args: Args): Option[_] =
if (args.argDefinedInQuery(name)) {
if (args.optionalArgs.contains(name)) {
args.argOpt(name)
Expand All @@ -1556,7 +1552,7 @@ private[execution] class FutureResolver[Ctx, Input](
def deprecatedArgsUsed(argDefs: List[Argument[_]], argValues: Args): List[Argument[_]] =
argDefs.filter { argDef =>
val argValue = getArgValue(argDef.name, argValues)
argDef.deprecationReason.isDefined && argValue.isDefined && iu.isDefined(argValue.get)
argDef.deprecationReason.isDefined && argValue.isDefined
}

def trackDeprecatedDirectiveArgs(astDirective: ast.Directive): Unit = {
Expand Down Expand Up @@ -1591,26 +1587,16 @@ private[execution] class FutureResolver[Ctx, Input](
}
}

def trackDeprecatedInputObjectFields(inputType: InputType[_], ioArg: Input): Unit =
def trackDeprecatedInputObjectFields(inputType: InputType[_], ioArg: Any): Unit =
inputType match {
case ioDef: InputObjectType[_] =>
ioDef.fields.foreach { field =>
// field deprecation
val fieldVal: Option[Input] = (ioArg match {
case lm: ListMap[String, Input] => lm.get(field.name)
case in: Input =>
try
if (iu.isMapNode(in)) {
val inputVal = iu.getMapValue(in, field.name)
Option.when(inputVal.isDefined && iu.isDefined(inputVal.get))(inputVal.get)
} else {
None
}
catch {
case _: Throwable => None
}
val fieldVal: Option[_] = (ioArg match {
case lm: ListMap[String, _] => lm.get(field.name)
case _ => None
}) match {
case Some(Some(nested: Input)) => Some(nested)
case Some(Some(nested)) => Some(nested)
case value => value
}

Expand All @@ -1626,19 +1612,13 @@ private[execution] class FutureResolver[Ctx, Input](
}
case OptionInputType(ofType) =>
ioArg match {
case Some(ioArg: Input) => trackDeprecatedInputObjectFields(ofType, ioArg)
case Some(ioArg) => trackDeprecatedInputObjectFields(ofType, ioArg)
case _ => trackDeprecatedInputObjectFields(ofType, ioArg)
}
case ListInputType(ofType) =>
ioArg match {
case seq: Seq[Input] => seq.foreach(trackDeprecatedInputObjectFields(ofType, _))
case in: Input =>
try
if (iu.isListNode(in))
iu.getListValue(in).foreach(trackDeprecatedInputObjectFields(ofType, _))
catch {
case _: Throwable => // do nothing
}
case seq: Seq[_] => seq.foreach(trackDeprecatedInputObjectFields(ofType, _))
case _ => // do nothing
}
case _ => // do nothing
}
Expand Down
10 changes: 3 additions & 7 deletions modules/core/src/main/scala/sangria/execution/Resolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package sangria.execution
import sangria.ast
import sangria.ast.SourceMapper
import sangria.execution.deferred.{Deferred, DeferredResolver}
import sangria.marshalling.{InputUnmarshaller, ResultMarshaller, ScalarValueInfo}
import sangria.marshalling.{ResultMarshaller, ScalarValueInfo}
import sangria.schema._

import scala.concurrent.ExecutionContext

private[execution] trait ResolverBuilder {
def build[Ctx, Input](
def build[Ctx](
marshaller: ResultMarshaller,
middlewareCtx: MiddlewareQueryContext[Ctx, _, _],
schema: Schema[Ctx, _],
Expand All @@ -27,11 +27,7 @@ private[execution] trait ResolverBuilder {
preserveOriginalErrors: Boolean,
validationTiming: TimeMeasurement,
queryReducerTiming: TimeMeasurement,
queryAst: ast.Document
)(implicit
executionContext: ExecutionContext,
iu: InputUnmarshaller[Input]
): Resolver[Ctx]
queryAst: ast.Document)(implicit executionContext: ExecutionContext): Resolver[Ctx]
}

private[execution] trait Resolver[Ctx] {
Expand Down

0 comments on commit acf8842

Please sign in to comment.