The current DSL for defining a union property uses a TypeID to specify the return type. However, this TypeID only refers to a type name and doesn't say anything about it's nullability. Similarly, it is not possible to speficy the TypeID of a list, so union properties can only ever return a single element.
To be precise, the following should be possible:
KGraphQL.schema {
val item = unionType("Item") {
type<Novel>()
type<NonFiction>()
}
type<BookShelf> {
unionProperty("items") {
returnType = item // problem: item cannot specify a list
resolver { _ ->
listOf(Novel("Peter Pan"), NonFiction("GraphQL"))
}
}
}
query("root") {
resolver { -> listOf(BookShelf("1"), BookShelf("2")) }
}
}
KGraphQL.schema {
val item = unionType("Item") {
type<Novel>()
type<NonFiction>()
}
type<BookShelf> {
unionProperty("items") {
returnType = item
resolver { shelf ->
if (shelf.id == "1") {
null // problem: returnType is non-nullable
} else {
NonFiction("GraphQL")
}
}
}
}
query("root") {
resolver { -> listOf(BookShelf("1"), BookShelf("2")) }
}
}
The current DSL for defining a union property uses a
TypeIDto specify the return type. However, thisTypeIDonly refers to a type name and doesn't say anything about it's nullability. Similarly, it is not possible to speficy theTypeIDof a list, so union properties can only ever return a single element.To be precise, the following should be possible: