Describe the bug
During the schema generation, building the code registry checks the WiringFactory to see if it can provide an item before checking explicitly registered items. This seems counter-intuitive. I would expect explicit registration of a data fetcher, type resolver, scalars, etc... to have the highest priority.
I think this could be as simple as reversing the if/else checks here to look for an explicit one first, then factory:
Scalars: https://github.com/graphql-java/graphql-java/blob/v20.1/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L438-L443
Interface type resolvers: https://github.com/graphql-java/graphql-java/blob/v20.1/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L504-L514
Union type resolvers: https://github.com/graphql-java/graphql-java/blob/v20.1/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L526-L536
Data Fetchers: https://github.com/graphql-java/graphql-java/blob/v20.1/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L836-L841
To Reproduce
Create wiring and register both an explicit type resolver in addition to a wiring factory.
var factory = new WiringFactory() {
@Override
public boolean providesTypeResolver(InterfaceWiringEnvironment environment) {
return true;
}
@Override
public TypeResolver getTypeResolver(InterfaceWiringEnvironment environment) {
return env -> env.getSchema().getQueryType();
}
};
var wiring = RuntimeWiring.newRuntimeWiring()
.wiringFactory(factory)
.type(TypeRuntimeWiring.newTypeWiring("MyType").typeResolver(env -> "FooType"))
.build();
When we query for something that returns MyType, we will receive an error about failing to resolve MyType to a concrete implementation.
Describe the bug
During the schema generation, building the code registry checks the
WiringFactoryto see if it can provide an item before checking explicitly registered items. This seems counter-intuitive. I would expect explicit registration of a data fetcher, type resolver, scalars, etc... to have the highest priority.I think this could be as simple as reversing the if/else checks here to look for an explicit one first, then factory:
Scalars: https://github.com/graphql-java/graphql-java/blob/v20.1/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L438-L443
Interface type resolvers: https://github.com/graphql-java/graphql-java/blob/v20.1/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L504-L514
Union type resolvers: https://github.com/graphql-java/graphql-java/blob/v20.1/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L526-L536
Data Fetchers: https://github.com/graphql-java/graphql-java/blob/v20.1/src/main/java/graphql/schema/idl/SchemaGeneratorHelper.java#L836-L841
To Reproduce
Create wiring and register both an explicit type resolver in addition to a wiring factory.
When we query for something that returns
MyType, we will receive an error about failing to resolveMyTypeto a concrete implementation.