-
-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: recursively translate input value strings to enums #1136
Conversation
) | ||
} yield assertTrue(res.data.toString == "{\"query\":\"BLUE\"}") | ||
}, | ||
testM("it doesn't allow strings as enums in GQL syntax") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is duplicated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, must've copy pasted too much. Sorry, was a tad stressed :D
case _ => value | ||
} | ||
case NamedType(name, _) => | ||
rootType.types.get(name).map(t => resolveEnumValues(value, t, rootType)).getOrElse(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if this one has a list inside. It doesn't need to recurse on this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lists should be handled here -- this is more that we need to special case the top level Type
before we get the "real" __Type
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be covered by this test case
caliban/core/src/test/scala/caliban/execution/FieldArgsSpec.scala
Lines 77 to 114 in 38daa5e
testM("it correctly handles lists of enums") { | |
case class QueryInput(color: List[COLOR], string: String) | |
case class Query(query: Field => QueryInput => UIO[String]) | |
val query = | |
"""query MyQuery($color: [COLOR!]!) { | |
| query(string: "test", color: $color) | |
|}""".stripMargin | |
for { | |
ref <- Ref.make[Option[Field]](None) | |
api = graphQL( | |
RootResolver( | |
Query( | |
query = info => { i => | |
ref.set(Option(info)).as(i.string) | |
} | |
) | |
) | |
) | |
interpreter <- api.interpreter | |
_ <- interpreter.executeRequest( | |
request = GraphQLRequest( | |
query = Some(query), | |
// "color" is a string here since it will come directly from | |
// parsed JSON which is unaware that it should be an Enum | |
variables = Some( | |
Map( | |
"color" -> | |
InputValue.ListValue(List(Value.StringValue("BLUE"))) | |
) | |
) | |
) | |
) | |
res <- ref.get | |
} yield assertTrue( | |
res.get.arguments("color") == InputValue.ListValue(List(EnumValue("BLUE"))) | |
) | |
}, |
Why this transformation necessary? I encountered same problem with validation of Int/Float. |
No description provided.