You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Union causes : Two different classes used for type #221
Hello,
There is a bug using union with a generic Bean.
Here's a schema snipet :
In root file :
union item = Order | User
type SearchResponse {
total: Int!
items: [item]
}
extend type Query {
orders(filter: OrderFilterInput): SearchResponse
users(filter: UserFilterInput): SearchResponse
}
So depending on the resolver, SearchReponse could have a List of items of type Order or User.
This rises this error:
Caused by: com.coxautodev.graphql.tools.SchemaClassScannerError: Two different classes used for type SearchResponse:
class com.api.graphql.common.core.SearchResponse:
| return type of method public com.api.graphql.common.core.SearchResponse com.api.graphql.order.OrderResolver.orders(com.api.graphql.order.OrderFilterInput)
class com.api.graphql.common.core.SearchResponse:
| return type of method public com.api.graphql.common.core.SearchResponse com.api.graphql.users.UserResolver.users(com.api.graphql.users.UserFilterInput)
Hello,
This is the hacky solution i've found, it's dirty but it works :
@Bean public SchemaParserDictionary dictionary() { return new SchemaParserDictionary().add(MyModelClassHere.class).add(AnotherMOdelCLass.class); }
all the classes involved in unions have to be added to the dictionnary.
Another possible solution is not to implement GraphQLQueryResolver but rather implement GraphQLResolver<MyModelClassHere> . I didn't test this enough because it breaks my current code, but i'm petty sure it could work.
Closing as a duplicate of #343. One GraphQL type cannot be backed by several parameterizations of a generic class. Use a shared type argument (SearchResponse<Any> or a common supertype) and add the union members to the dictionary. The broader request is tracked in #111.
Activity
AdamSoufiane commentedon Feb 17, 2019
Hello,
This is the hacky solution i've found, it's dirty but it works :
@Bean public SchemaParserDictionary dictionary() { return new SchemaParserDictionary().add(MyModelClassHere.class).add(AnotherMOdelCLass.class); }all the classes involved in unions have to be added to the dictionnary.
Another possible solution is not to implement GraphQLQueryResolver but rather implement
GraphQLResolver<MyModelClassHere>. I didn't test this enough because it breaks my current code, but i'm petty sure it could work.oryan-block commentedon Oct 3, 2026
Closing as a duplicate of #343. One GraphQL type cannot be backed by several parameterizations of a generic class. Use a shared type argument (
SearchResponse<Any>or a common supertype) and add the union members to the dictionary. The broader request is tracked in #111.