From 38daa5e892b803a4d370d4d565beeeac23dc4882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20W=C3=A4rnsberg?= Date: Thu, 11 Nov 2021 16:14:24 +0100 Subject: [PATCH] Pr comments --- .../caliban/parsing/VariablesUpdater.scala | 12 +++++------ .../caliban/execution/FieldArgsSpec.scala | 21 ------------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/core/src/main/scala/caliban/parsing/VariablesUpdater.scala b/core/src/main/scala/caliban/parsing/VariablesUpdater.scala index c2344b5f3..9a249d295 100644 --- a/core/src/main/scala/caliban/parsing/VariablesUpdater.scala +++ b/core/src/main/scala/caliban/parsing/VariablesUpdater.scala @@ -4,10 +4,8 @@ import caliban.GraphQLRequest import caliban.InputValue.ListValue import caliban.Value.StringValue import caliban.introspection.adt._ -import caliban.introspection.adt.__TypeKind import caliban.parsing.adt.Definition.ExecutableDefinition.OperationDefinition -import caliban.parsing.adt.Type.ListType -import caliban.parsing.adt.Type.NamedType +import caliban.parsing.adt.Type.{ ListType, NamedType } import caliban.parsing.adt._ import caliban.schema.RootType import caliban.{ InputValue, Value } @@ -24,7 +22,7 @@ object VariablesUpdater { val v = variableDefinitions .find(_.name == key) - .map { (definition: VariableDefinition) => + .map { definition => rewriteValues(value, definition.variableType, rootType) } .getOrElse(value) @@ -35,15 +33,15 @@ object VariablesUpdater { req.copy(variables = Some(updated)) } - def rewriteValues(value: InputValue, `type`: Type, rootType: RootType): InputValue = + private def rewriteValues(value: InputValue, `type`: Type, rootType: RootType): InputValue = `type` match { - case ListType(ofType, nonNull) => + case ListType(ofType, _) => value match { case ListValue(values) => ListValue(values.map(v => rewriteValues(v, ofType, rootType))) case _ => value } - case NamedType(name, nonNull) => + case NamedType(name, _) => rootType.types.get(name).map(t => resolveEnumValues(value, t, rootType)).getOrElse(value) } diff --git a/core/src/test/scala/caliban/execution/FieldArgsSpec.scala b/core/src/test/scala/caliban/execution/FieldArgsSpec.scala index f2ebb5f9d..e406269e5 100644 --- a/core/src/test/scala/caliban/execution/FieldArgsSpec.scala +++ b/core/src/test/scala/caliban/execution/FieldArgsSpec.scala @@ -215,27 +215,6 @@ object FieldArgsSpec extends DefaultRunnableSpec { ) ) } yield assertTrue(res.data.toString == "{\"query\":\"BLUE\"}") - }, - testM("it doesn't allow strings as enums in GQL syntax") { - case class QueryInput(color: COLOR) - case class Query(query: QueryInput => UIO[String]) - val query = - """query { - | query(color: "BLUE") - |}""".stripMargin - - val api = graphQL( - RootResolver( - Query( - query = i => ZIO.succeed(i.toString) - ) - ) - ) - - for { - interpreter <- api.interpreter - res <- interpreter.execute(query) - } yield assert(res.errors.headOption)(isSome(anything)) } ) }