Skip to content

Commit

Permalink
Pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
frekw committed Nov 11, 2021
1 parent b078f5e commit 38daa5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 28 deletions.
12 changes: 5 additions & 7 deletions core/src/main/scala/caliban/parsing/VariablesUpdater.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -24,7 +22,7 @@ object VariablesUpdater {
val v =
variableDefinitions
.find(_.name == key)
.map { (definition: VariableDefinition) =>
.map { definition =>
rewriteValues(value, definition.variableType, rootType)
}
.getOrElse(value)
Expand All @@ -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)
}

Expand Down
21 changes: 0 additions & 21 deletions core/src/test/scala/caliban/execution/FieldArgsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
)
}

0 comments on commit 38daa5e

Please sign in to comment.