Skip to content
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

Fixing Caliban integration & adding quill-caliban to build #44

Merged
merged 1 commit into from
Dec 29, 2021

Conversation

deusaquilus
Copy link
Contributor

@deusaquilus deusaquilus commented Dec 29, 2021

Caliban productArgs were not properly being handled, they were only being passed in on the top level.
Also, in flattenToPairs, strings had ""ExtraQuotes"" around them.
Also added tests for many more cases with nested data.

Note that unless the Caliban schema is correctly matched to the output data, Circe deserialization will cause NPEs.
For example when the graphQL query:

{
  personAddressNested(id: 1) {
    id
    age
    name {
      first
      last
    }
  }
}

And the following schema & query:

case class Name(first: String, last: String)
case class PersonT(id: Int, name: Name, age: Int)
case class AddressT(ownerId: Int, street: String)
case class PersonAddressNested(id: Int, name: Name, age: Int, street: Option[String])

query[PersonT].leftJoin(query[AddressT]).on((p, a) => p.id == a.ownerId)
  .map((p, a) => PersonAddressNested(p.id, p.name, p.age, a.map(_.street)))
  .filterByKeys(filters)
  .filterColumns(columns)
  .take(10)

If the caliban integration messes up and does not pass any of the columns: List("id", "age", "first", "last") into the columns variable being passed to the query.... let's say the last two columns are missing: columns:List("id", "age") then the resulting data will look like:

List(
PersonAddressNested(1, Name(null, null), 44)
)

Instead of:

List(
PersonAddressNested(1, Name("One", "A"), 44)
)

Circe will cause an NPE during deserialization. On the caliban side it will look like this:

java.lang.NullPointerException:
  at caliban.Value$StringValue.toString(Value.scala:74)
  at caliban.ResponseValue$ObjectValue.toString$$anonfun$1(Value.scala:39)
  at scala.collection.immutable.List.map(List.scala:246)
  at caliban.ResponseValue$ObjectValue.toString(Value.scala:39)

If you are running it from ZIO-Http it will look like this:

[error] Fiber failed.
[error] An unchecked error was produced.
[error] java.lang.NullPointerException
[error]         at io.circe.Printer$PrintingFolder.onString(Printer.scala:309)
[error]         at io.circe.Printer$PrintingFolder.onString(Printer.scala:303)
[error]         at io.circe.Json$JString.foldWith(Json.scala:364)
[error]         at io.circe.JsonObject$LinkedHashMapJsonObject.appendToFolder(JsonObject.scala:343)
[error]         at io.circe.Printer$PrintingFolder.onObject(Printer.scala:359)
[error]         at io.circe.Printer$PrintingFolder.onObject(Printer.scala:359)
[error]         at io.circe.Json$JObject.foldWith(Json.scala:426)
[error]         at io.circe.JsonObject$LinkedHashMapJsonObject.appendToFolder(JsonObject.scala:343)
[error]         at io.circe.Printer$PrintingFolder.onObject(Printer.scala:359)
[error]         at io.circe.Printer$PrintingFolder.onObject(Printer.scala:359)
[error]         at io.circe.Json$JObject.foldWith(Json.scala:426)
[error]         at io.circe.Printer$PrintingFolder.onArray(Printer.scala:345)
[error]         at io.circe.Printer$PrintingFolder.onArray(Printer.scala:335)
[error]         at io.circe.Json$JArray.foldWith(Json.scala:395)
[error]         at io.circe.JsonObject$LinkedHashMapJsonObject.appendToFolder(JsonObject.scala:343)
[error]         at io.circe.Printer$PrintingFolder.onObject(Printer.scala:359)
[error]         at io.circe.Printer$PrintingFolder.onObject(Printer.scala:359)
[error]         at io.circe.Json$JObject.foldWith(Json.scala:426)
[error]         at io.circe.JsonObject$LinkedHashMapJsonObject.appendToFolder(JsonObject.scala:343)
[error]         at io.circe.Printer$PrintingFolder.onObject(Printer.scala:359)
[error]         at io.circe.Printer$PrintingFolder.onObject(Printer.scala:359)
[error]         at io.circe.Json$JObject.foldWith(Json.scala:426)
[error]         at io.circe.Printer.print(Printer.scala:194)
[error]         at io.circe.Json.spaces2(Json.scala:122)
[error]         at io.circe.Json.toString(Json.scala:215)
[error]         at caliban.ZHttpAdapter$.caliban$ZHttpAdapter$$anon$2$$_$applyOrElse$$anonfun$2$$anonfun$1(ZHttpAdapter.scala:107)
[error]         at zio.ZIO$MapFn.apply(ZIO.scala:4438)

@deusaquilus deusaquilus merged commit d840c21 into master Dec 29, 2021
@deusaquilus deusaquilus deleted the caliban-updates branch December 29, 2021 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant