try to reproduce issue #1041#1156
Draft
yanns wants to merge 2 commits into
Draft
Conversation
|
@yanns I think there should be something like this, it should reproduce the issue: object IOExecutionSchemeSpec {
import sangria.catseffect.schema.AsyncValue._
private def resolve[F[_]: Async](): F[String] = {
import cats.syntax.functor._
Async[F].pure(Option("hello")).map {
case Some(value) => value
case None => throw new Exception("No value")
}
}
private val QueryType: ObjectType[Unit, Unit] = ObjectType(
"Query",
() =>
fields[Unit, Unit](
Field("ids", ListType(IntType), resolve = _ => List(1, 2)),
Field(
"parent",
StringType,
resolve = { _ => resolve[IO]() }
)
)
)
private val schema = Schema(QueryType)
} |
Contributor
Author
|
Thanks, I can now reproduce the issue. |
|
@yanns I played around with this issue a bit, maybe we could use something like this: def async[Ctx, Val, Res, Out, F[_]](
name: String,
fieldType: OutputType[Out],
description: Option[String] = None,
arguments: List[Argument[_]] = Nil,
resolve: Context[Ctx, Val] => F[Res],
possibleTypes: => List[PossibleObject[_, _]] = Nil,
tags: List[FieldTag] = Nil,
complexity: Option[(Ctx, Args, Double) => Double] = None,
deprecationReason: Option[String] = None,
astDirectives: Vector[ast.Directive] = Vector.empty
)(implicit ev: ValidOutType[Res, Out],
asyncToAction: (Context[Ctx, Val] => F[Res]) => Context[Ctx, Val] => Action[Ctx, Res]): Field[Ctx, Val] =
Field[Ctx, Val](
name,
fieldType,
description,
arguments,
asyncToAction(resolve),
deprecationReason,
tags,
complexity,
() => possibleTypes.map(_.objectType),
astDirectives,
Vector.empty)and the resolver implicit conversion: object AsyncResolver {
implicit def asyncToAction[Ctx, Val, Res, F[_]: Async](resolver: Context[Ctx, Val] => F[Res]): Context[Ctx, Val] => Action[Ctx, Res] = {
context => AsyncValue(resolver(context))
}
}This will require an additional signature for Field, but we’ll avoid the ambiguity issue. Or alternatively, we could simply expose the |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.