-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GraphQL schema generation fails with sealed interfaces #2237
Comments
I do not think that we support polymorphism (maybe someone can double check me) of this kind, instead what we use is So, if you just annotate the interface like this: // the rest of the code ...
@Union
sealed interface CustomerProduct permits InternetLine, MobileLine {
String name();
}
// the rest of the code ... It will create a GraphQL schema like this: union CustomerProduct = InternetLine | MobileLine
type InternetLine {
name: String
speed: Int!
}
type MobileLine {
mobileNumber: String
name: String
}
"Query root"
type Query {
products: [CustomerProduct]
}
And GraphQL request can look like this (by enumerating all the children): query {
products {
... on MobileLine {
name
# mobileNumber
}
... on InternetLine {
name
# speed
}
}
} Response: {
"data": {
"products": [
{
"name": "Test"
},
{
"name": "Test"
}
]
}
} |
@mskacelik but it works in kotlin without the union @GraphQLApi
class HelloGraphQLResource {
@Query("customerProducts")
@Description("return all customer products")
fun sayHello(name: String): CustomerProducts {
return CustomerProducts(
mobileLines = listOf(
CustomerProduct.MobileLine("1", "12345678")
),
internetLine = listOf(
CustomerProduct.InternetLine("3", 100)
)
)
}
}
data class CustomerProducts(
val mobileLines: List<CustomerProduct>,
val internetLine: List<CustomerProduct>
)
sealed interface CustomerProduct {
val id: String
data class MobileLine(override val id: String, val phoneNumber: String) : CustomerProduct
data class InternetLine(override val id: String, val speed: Int) : CustomerProduct
} creates a schema interface CustomerProduct {
id: String!
}
type CustomerProducts {
internetLine: [CustomerProduct]!
mobileLines: [CustomerProduct]!
}
type InternetLine implements CustomerProduct {
id: String!
speed: Int!
}
type MobileLine implements CustomerProduct {
id: String!
phoneNumber: String!
}
"Query root"
type Query {
"return all customer products"
customerProducts(name: String!): CustomerProducts!
} |
@faskan Oh, now I understand. The problem was this line: Line 41 in 95641c9
We only accepted output property methods getXXX for the interfaces, which is a problem with records since it does not follow the getXXX/setXXX, unlike classes.
I made a PR with a possible solution of allowing the creation of fields for the interfaces with the @org.eclipse.microprofile.graphql.Name` annotation: interface Interface {
@Name("name") // @Name("") also works
String name();
} PR: #2238 |
Quarkus startup and GraphQL schema generation fails with sealed interfaces.
Here is my reproducer.
Full source code in github - https://github.com/faskan/graphql
Running this code results in "type not found in schema" exception.
Stacktrace:
I saw similar issue reported in quarkusio/quarkus#12846 but seemed like it was raised for kotlin and for kotlin it works well with sealed interfaces and data classes.
The text was updated successfully, but these errors were encountered: