Skip to content

Commit

Permalink
throw better exception when a resolver is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
yanns committed Jun 27, 2024
1 parent 3b74ffb commit 701096f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion core/src/main/scala/sangria/federation/v1/Federation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ object Federation {
"_entities" -> (ctx =>
ctx.withArgs(representationsArg) { anys =>
Action.sequence(anys.map { any =>
val resolver = resolversMap(any.__typename)
val typeName = any.__typename
val resolver = resolversMap.getOrElse(
typeName,
throw new Exception(s"no resolver found for type '$typeName'"))

any.fields.decode[resolver.Arg](resolver.decoder) match {
case Right(value) => resolver.resolve(value, ctx)
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/scala/sangria/federation/v2/Federation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ object Federation {
"_entities" -> (ctx =>
ctx.withArgs(representationsArg) { anys =>
Action.sequence(anys.map { any =>
val resolver = resolversMap(any.__typename)
val typeName = any.__typename
val resolver = resolversMap.getOrElse(
typeName,
throw new Exception(s"no resolver found for type '$typeName'"))

any.fields.decode[resolver.Arg](resolver.decoder) match {
case Right(value) => resolver.resolve(value, ctx)
Expand Down

0 comments on commit 701096f

Please sign in to comment.