Open
Description
The issue is relevant for 5.3.1+.
I'm trying to create an interface with a polymorphic connection field, which requires interface to declare it as a union of all implementation types, something like
union AnyConnection = XConnection | YConnection
# connection and edge definitions...
interface WithConnection {
connection: AnyConnection!
}
type WithXConnection {
connection: XConnection!
}
type WithYConnection {
connection: YConnection!
}
However, trying to do something like this fails on com.coxautodev.graphql.tools.TypeResolverError: Expected object type with name 'DefaultConnection' to exist for union 'AnyConnection', but it doesn't!
.
My reproducer, based on relay connection test:
public class Test {
static class QueryResolver implements GraphQLQueryResolver {
Connection<User> users(int first, String after, DataFetchingEnvironment env) {
return new SimpleListConnection<User>(List.of(new User(1L, "name"))).get(env);
}
Connection<AnotherType> otherTypes(DataFetchingEnvironment env) {
return new SimpleListConnection<AnotherType>(List.of(new AnotherType("echo"))).get(env);
}
Object any(DataFetchingEnvironment env) {
return new SimpleListConnection<AnotherType>(List.of(new AnotherType("echo"))).get(env);
}
}
static class User {
Long id;
String name;
User(Long id, String name) {
this.id = id;
this.name = name;
}
}
static class AnotherType {
String echo;
AnotherType(String echo) {
this.echo = echo;
}
}
public static void main(String[] args) {
var schemaString = " type Query {\n" +
" users(first: Int, after: String): UserConnection\n" +
" otherTypes: AnotherTypeConnection\n" +
" any: AnyConnection!\n" +
" }\n" +
" type UserConnection {\n" +
" edges: [UserEdge!]!\n" +
" pageInfo: PageInfo!\n" +
" }\n" +
" \n" +
" type UserEdge {\n" +
" node: User!\n" +
" }\n" +
" \n" +
" type User {\n" +
" id: ID!\n" +
" name: String\n" +
" }\n" +
" \n" +
" type PageInfo {\n" +
" }\n" +
" \n" +
" type AnotherTypeConnection {\n" +
" edges: [AnotherTypeEdge!]!\n" +
" }\n" +
" \n" +
" type AnotherTypeEdge {\n" +
" node: AnotherType!\n" +
" }\n" +
" \n" +
" type AnotherType {\n" +
" echo: String\n" +
" }\n" +
"\n" +
" union AnyConnection = UserConnection | AnotherTypeConnection";
var schema = SchemaParser.newParser().schemaString(schemaString)
.resolvers(new QueryResolver())
.build()
.makeExecutableSchema();
var gql = GraphQL.newGraphQL(schema)
.queryExecutionStrategy(new AsyncExecutionStrategy())
.build();
var query = "query {\n" +
" any {\n" +
" ...on AnotherTypeConnection {\n" +
" edges {\n" +
" node {\n" +
" echo\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
" }";
System.out.println(gql.execute(query));
}
}
The culprit appears to be
It seems to try to do all the autowiring magic, but Connection types have class names that are different from GraphQL types. Adding dictionaries won't help also, since they're all DefaultConnection
.