Skip to content

Support nullable unionType and lists #700

Description

@stuebingerb

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")) }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions