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

ClassCastException not very helpful when misconfigured either schema or resolver

Open XanderAtBackboneSystems opened this issue 6 years ago • 0 comments

When i tried to return a Connection in a resolver which would be coupled to a simple list type in the graphql schema (which is evidently wrong) i got the following error which is not very helpful.

java.lang.ClassCastException: com.coxautodev.graphql.tools.ParameterizedTypeImpl cannot be cast to java.lang.Class

I suppose a better detection and a better error message would be helpful when making this kind of errors.

using the following graphql-java version: 13.0 graphql-java-tools version: 5.6.1

To reproduce:

schema:

type Query {
   findBlips: [Blip!]!
}

type Blip {
 foo: String
 bar: String 
}

resolver

public class QueryResolver implements GraphQLQueryResolver {
    public Connection<Blip> findBlips(DataFetchingEnvironment env) {
        List<Blip> blips = findBlips();
        return new SimpleListConnection<>(blips).get(env);
    }
}

Hope you can improve the error...

The stack trace is:

java.lang.ClassCastException: com.coxautodev.graphql.tools.ParameterizedTypeImpl cannot be cast to java.lang.Class
	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)
	at com.coxautodev.graphql.tools.SchemaClassScanner.handleRootType(SchemaClassScanner.kt:119)
	at com.coxautodev.graphql.tools.SchemaClassScanner.scanForClasses(SchemaClassScanner.kt:77)
	at com.coxautodev.graphql.tools.SchemaParserBuilder.scan(SchemaParserBuilder.kt:165)
	at com.coxautodev.graphql.tools.SchemaParserBuilder.build(SchemaParserBuilder.kt:206)
	<removed>

XanderAtBackboneSystems avatar Jul 09 '19 09:07 XanderAtBackboneSystems