graphql-java-annotations icon indicating copy to clipboard operation
graphql-java-annotations copied to clipboard

"There must be a type resolver for interface" with @GraphQLTypeResolver, type resolver is not visible

Open maximd1 opened this issue 4 years ago • 1 comments

Hi,

we are facing an issue with @GraphQLTypeResolver annotation while migrating from 5.4 to the latest 7.2.1. Issue is that our type resolver is not visible by GraphQL:

graphql.AssertException: There must be a type resolver for interface TaxonomyItem

Here is an example of our code:

@GraphQLTypeResolver(TaxonomyResolver.class)
@GraphQLDescription("Represents a taxonomy item.")
public interface TaxonomyItem extends Item {
...

Here is how we initalize GraphQLAnnotations. StructureGroup class extends TaxonomyItem. It was working in version 5.4:

GraphQLAnnotations graphQLAnnotations = new GraphQLAnnotations();
Set<GraphQLType> internalTypes = new HashSet<>();
internalTypes.add(graphQLAnnotations.object(StructureGroup.class));
...
GraphQLSchema schema = newSchema()
                .query(graphQLAnnotations.object(ContentQuery.class))
                .additionalTypes(internalTypes)
                .build();
graphQL = GraphQL.newGraphQL(schema).build();

During our investigations we've found that newest (7.2.1) InterfaceBuilder.getInterfaceBuilder method returns wrong builder:

GraphQLTypeResolver typeResolver = iface.getAnnotation(GraphQLTypeResolver.class);
container.getCodeRegistryBuilder().typeResolver(typeName, newInstance(typeResolver.value()));
return builder; // << this is a builder with an empty typeResolver!

As we can see in debug, container.getCodeRegistryBuilder() returns correct builder, but getInterfaceBuilder method returns other builder, where typeResolverMap is null.

Version 6 does this a little bit simpler:

GraphQLTypeResolver typeResolver = iface.getAnnotation(GraphQLTypeResolver.class);
builder.typeResolver(newInstance(typeResolver.value()));
return builder;

Is there any stuff we missed?

maximd1 avatar Dec 05 '19 16:12 maximd1

The typeResolver field inside the GraphQLInterfaceType builder is deprecated. GraphQL-Java uses the type resolver inside the CodeRegistry. I wonder why it does not work for you, because I checked and interfaces with resolver works just fine in 7.2.1. Maybe you don't use the AnnotationsSchemaCreator correctly?

yarinvak avatar Jan 17 '20 16:01 yarinvak

Hi @maximd1 ,

We're helping with project maintenance and reviewing the list of opened PRs and Issues.

This issue was created quite a while ago, we were wondering if you were still interested in the outcome, please let us know if this is the case.

Without an answer by July 1st, 2023, this issue will be closed as "inactive" (and can always be re-opened later on if needed).

Thanks,

Fgerthoffert avatar Jun 02 '23 08:06 Fgerthoffert