-
Notifications
You must be signed in to change notification settings - Fork 222
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
How to provide nested list of case class as an argument to the GQL query #715
Comments
I've been running into the same issue and believe that it's a bug. Did you find a way around this? |
If you are using spray-json, you should use https://github.com/sangria-graphql/sangria-spray-json/blob/main/src/main/scala/sangria/marshalling/sprayJson.scala somewhere. It's strange that it does not appear in the stack trace. |
@yanns I've looked into the issue more, and I'm convinced it is a bug with sangria. I created a test case for it on my own fork, located here. I should note that although this test and the above issue use spray-json, I have been running into the same issue with circe. The issue seems to stem from a lack of type safety within the default I have been able to circumvent this issue by creating my own implementation of case class SeqInput[T](delegate: FromInput[T]) extends FromInput.SeqFromInput[T](delegate) {
override def fromResult(node: marshaller.Node): Seq[T] = {
super.fromResult(nodeToVector(node).asInstanceOf[marshaller.Node])
}
private def nodeToVector(node: marshaller.Node): Vector[_] =
node match {
case json: Json =>
json.asArray
// the get or else will fail, but there's no way to recover
.getOrElse(json.asInstanceOf[Vector[_]])
case _ => node.asInstanceOf[Vector[_]]
}
}
case class OptInput[T](delegate: FromInput[T]) extends FromInput[Option[T]] {
override val marshaller: ResultMarshaller = delegate.marshaller
override def fromResult(node: marshaller.Node): Option[T] = {
node match {
case opt: Option[_] => opt.map(elem => delegate.fromResult(elem.asInstanceOf[delegate.marshaller.Node]))
case elem => Some(delegate.fromResult(elem.asInstanceOf[delegate.marshaller.Node]))
}
}
} Clearly, these are circe specific and do not work in the general case. However, they help demonstrate what the issue is and function as a stopgap solution for now. Unfortunately, I am not too familiar with the sangria source code, so I'm not sure if I'd be able to fix this myself. It seems to me that a solution might involve having |
Thanks for the detailed information. Yes, it seems you found something.. How to tackle this:
If someone wants to try this, please comment. |
Related to #449 |
One of the input of the GQL query is the nested list of case class.
For ex:
case class User (id: Int, name:String)
when I run the application I am getting the following error:
input request:
Any help will be appriciated. Thanks
The text was updated successfully, but these errors were encountered: