Skip to content

[Question] How to properly change the default properties of a sealed class? #147

@NathanPB

Description

@NathanPB

Hello, I'm trying to build a data structure that looks like this:

@Serializable
sealed class Person {

    @Serializable
    class Internal(val uid: String) : Person() {
        val profile: UserProfile?
            get() = findUserById(uid)
    }

    @Serializable
    class External(val email: String, val name: String) : Person()
}
unionType<Person>() {
        type<Person.Internal>() {
            property(Person.Internal::uid) {}
            property(Person.Internal::profile) {}
        }

        type<Person.External>()
    }

The thing actually works as expected, but when I open the Playground I lose the autocomplete and I see this error in the browser console: Uncaught Error: Expected Person to be a GraphQL Interface type..

Since it works it's acceptable, but losing the autocomplete is annoying. Any suggestions on how to make this work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions