graphql-java-kickstart / graphql-spring-boot

GraphQL and GraphiQL Spring Framework Boot Starters - Forked from oembedler/graphql-spring-boot due to inactivity.
https://www.graphql-java-kickstart.com/spring-boot/
MIT License
1.51k stars 324 forks source link

ParameterizedTypeImpl cannot be cast to class java.lang.Class #359

Closed ptahchiev closed 4 years ago

ptahchiev commented 4 years ago

I have the following controller:

public interface IndividualProviderController extends GraphQLQueryResolver, GraphQLMutationResolver {

    String NAME = "individualProviderController";

    ResponseEntity<IndividualProviderResponseDtoDefinition> findByCode(@Nonnull final String individualProviderCode);

and I have this SchemaParser:

    @Bean
    public SchemaParser defaultGraphQLSchemaProvider(@Qualifier(IndividualProviderController.NAME) IndividualProviderController individualProviderController) {
        return SchemaParser.newParser().file("graphql/individualProvider.graphqls").resolvers(individualProviderController).build();
    }

but when I start my application I get this error:

Caused by: java.lang.ClassCastException: class com.coxautodev.graphql.tools.ParameterizedTypeImpl cannot be cast to class java.lang.Class (com.coxautodev.graphql.tools.ParameterizedTypeImpl is in unnamed module of loader 'app'; java.lang.Class is in module java.base of loader 'bootstrap')
    at com.coxautodev.graphql.tools.TypeClassMatcher.match(TypeClassMatcher.kt:81)
    at com.coxautodev.graphql.tools.TypeClassMatcher.match$default(TypeClassMatcher.kt:32)
    at com.coxautodev.graphql.tools.TypeClassMatcher.match(TypeClassMatcher.kt:75)
    at com.coxautodev.graphql.tools.TypeClassMatcher.match(TypeClassMatcher.kt:28)
    at com.coxautodev.graphql.tools.SchemaClassScanner.scanResolverInfoForPotentialMatches(SchemaClassScanner.kt:268)

and indeed on line 81 in TypeClassMatcher the realType is of type ResponseEntity which is ParameterizedTypeImpl

voychris commented 4 years ago

I’m facing the same issue after upgrading from 5.9.0 to 6.0.1

oliemansm commented 4 years ago

This is a question for graphql-java-tools, not spring boot.

What is your idea with the ResponseEntity here? Because that's not used in graphl-spring-boot. You should just return the object directly instead.

oliemansm commented 4 years ago

My guess is if you remove the ResponseEntity and just return the class directly it will work. Feel free to re-open if you still run into a problem.