From 701096f70c2d5ccd6097a575920a0869c3418275 Mon Sep 17 00:00:00 2001 From: Yann Simon Date: Thu, 27 Jun 2024 12:23:14 +0200 Subject: [PATCH] throw better exception when a resolver is not found --- core/src/main/scala/sangria/federation/v1/Federation.scala | 5 ++++- core/src/main/scala/sangria/federation/v2/Federation.scala | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/sangria/federation/v1/Federation.scala b/core/src/main/scala/sangria/federation/v1/Federation.scala index 00d6d51..28e5fa7 100644 --- a/core/src/main/scala/sangria/federation/v1/Federation.scala +++ b/core/src/main/scala/sangria/federation/v1/Federation.scala @@ -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) diff --git a/core/src/main/scala/sangria/federation/v2/Federation.scala b/core/src/main/scala/sangria/federation/v2/Federation.scala index deaf43a..f2ae7e4 100644 --- a/core/src/main/scala/sangria/federation/v2/Federation.scala +++ b/core/src/main/scala/sangria/federation/v2/Federation.scala @@ -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)