`fieldWithArgs` breaks list optionality of fields
paulpdaniels opened this issue · comments
Consider:
import caliban._
import caliban.schema._
case class MyArgs(int: Int)
case class Query(
values: MyArgs => List[String],
values1: MyArgs => String
)
implicit val myArgsSchema: Schema[Any, MyArgs] = Schema.gen
implicit val myArgsBuilder: ArgBuilder[MyArgs] = ArgBuilder.gen
implicit val schema: Schema[Any, Query] = Schema.obj("Query")(
implicit fa => List(
Schema.fieldWithArgs("values")(_.values),
Schema.fieldWithArgs("values1")(_.values1)
)
)
val api = graphQL(RootResolver(Query(_ => Nil, _ => "")))
api.render
This prints:
schema {
query: Query
}
type Query {
values(int: Int!): [String!]
values1(int: Int!): String
}
Which makes the return value optional instead of non-null as it should be (note that this doesn't happen with Schema.gen
or auto derivation, no does it happen with a normal arg-less field.
Reproduction: https://scastie.scala-lang.org/Dv987mCCRtqQbBDLRysUlg
It should be changed to () => if (ev1.optional) t else t.nonNull
with t = ev1.toType_(fa.isInput, fa.isSubscription)
.