I'm having a hard time registering a @SchemaMapping function that should be used as a data fetcher for all subclasses for an interface.
Given the example schema:
interface User {
username: String!
color: String!
}
type PurpleUser implements User {
username: String!
color: String!
}
type GreenUser implements User {
username: String!
color: String!
}
type Query {
userGet(username: String): User
}
And the following Kotlin model:
interface User {
val username: String
}
data class PurpleUser(override val username: String) : User
data class GreenUser(override val username: String) : User
My expectation is that by defining a schema mapping for the User interface I would be able to register a data fetcher for the color field on all User subclasses.
@SchemaMapping(typeName = "User", field = "color")
fun mapColor(user: User): String {
return when(user.username) {
"purpleUser" -> "purple"
"greenUser" -> "green"
else -> throw RuntimeException()
}
}
However in this example the following query:
{
userGet(username: "green") {
username
color
}
}
Results in an exception.
{
"errors": [
{
"message": "The field at path '/userGet/color' was declared as a non null type
....
Registering a @SchemaMapping for both concrete types (PurpleUser and GreenUser) fixes this issue.
Is it possible to configure this in a way to avoid duplication of mapping annotations across concrete subtypes? I've included a sample project that demonstrates this issue.
I'm having a hard time registering a
@SchemaMappingfunction that should be used as a data fetcher for all subclasses for an interface.Given the example schema:
And the following Kotlin model:
My expectation is that by defining a schema mapping for the
Userinterface I would be able to register a data fetcher for thecolorfield on allUsersubclasses.However in this example the following query:
Results in an exception.
Registering a
@SchemaMappingfor both concrete types (PurpleUser and GreenUser) fixes this issue.Is it possible to configure this in a way to avoid duplication of mapping annotations across concrete subtypes? I've included a sample project that demonstrates this issue.