Skip to content

Version 8.8.1 ktor does not generate interface or sealed class subtypes into GraphQL types #2127

@njlang10

Description

@njlang10

Library Version
8.8.1

Describe the bug
Also mentioned here (#2074). When running the example for interfaces https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/writing-schemas/interfaces/, and querying the animal type, I receive an error because the subtypes of the interface don't get generated as GraphQL types.

To Reproduce
Steps to reproduce the behavior. Please provide:

  • Schema Configuration
enum class AnimalTypes {
    CAT,
    DOG
}

interface Animal {
    val type: AnimalTypes
    fun sound(): String
}

class Cat : Animal {
    override val type = AnimalTypes.CAT

    override fun sound() = "meow"

    fun ignoreEveryone(): String = "ignore everyone"
}

class Dog : Animal {
    override val type = AnimalTypes.DOG

    override fun sound() = "bark"

    fun barkAtEveryone(): String = "bark at everyone"
}
  • Query
query { animalType(type: CAT) { type }}
  • Error Response
  "errors": [
    {
      "message": "Can't resolve '/getAnimalByType'. Abstract type 'Animal' must resolve to an Object type at runtime for field 'Query.getAnimalByType'. Could not determine the exact type of 'Animal'",
      "path": [
        "getAnimalByType"
      ]
    }
  ]
}

In graphiql, you can also see the subtypes don't exist

Image

Expected behavior
Interfaces should generate the subtypes and the query should succeed

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions