Open mxmlnglt opened 4 years ago
My only workaround for now is to move the implements GraphQLResolver<T>
to the actual resolver:
@Component
public abstract class MotherResolver<T extends Mother> implements GraphQLResolver<T> { // can be removed from here, it's totally useless...
// Resolving methods for Mother's fields
}
@Component
public class ChildResolver extends MotherResolver<Child> implements GraphQLResolver<Child> { // totally needed here
// Resolving methods for Child's fields
}
Edit: fixed from GraphQLResolver<T>
to GraphQLResolver<Child>
in the ChildResolver
, thanks @geeseen
@Component public class ChildResolver extends MotherResolver<Child> implements GraphQLResolver<T> { // totally needed here // Resolving methods for Child's fields }
Did you mean:
@Component public class ChildResolver extends MotherResolver<Child> implements GraphQLResolver<Child> { ...}
?
@Component public class ChildResolver extends MotherResolver<Child> implements GraphQLResolver<T> { // totally needed here // Resolving methods for Child's fields }
Did you mean:
@Component public class ChildResolver extends MotherResolver<Child> implements GraphQLResolver<Child> { ...}
?
Oh yeah, right, I missed this before posting (probably just a copy-paste problem).
Ok, as suspected ;-)
Unfortunately, it doesn't work for me if I move the GraphQLResolver
from the superclass down to the actual class, when there is also a generic typed method in the super class.
For example, if I have the following:
@Component
public abstract class MotherResolver<T extends Mother> {
public T getNext(){
return ...
}
}
This is not working (No type variable found for T)
@Component
public class ChildResolver extends MotherResolver<Child> implements GraphQLResolver<Child> {
}
But, if I explicitly overwrite the method and call its super method, it is working:
@Component
public class ChildResolver extends MotherResolver<Child> implements GraphQLResolver<Child> {
public Child getNext(){
return super.getNext();
}
}
Of course, this is only an interim solution, because the child resolvers are then inflated unnecessarily and the advantage of Java inheritance does not pay off here - quite apart from the non-existing DRY principle.
Normally, you should be able to define methods centrally in the MotherResolver
, which then also apply to all ChildResolvers
, without having to touch the ChildResolver
individually.
Normally, you should be able to define methods centrally in the
MotherResolver
, which then also apply to allChildResolvers
, without having to touch theChildResolver
individually.
Yes, exactly. That's what I do.
Normally, you should be able to define methods centrally in the
MotherResolver
, which then also apply to allChildResolvers
, without having to touch theChildResolver
individually.Yes, exactly. That's what I do.
And it is working for you?
graphql-java-tools could not parse the <T>
in
MotherResolver<T extends SomeObj> implements GraphQLResolver<T>
,
we need do this.
Any updates on this?
I'm building a sample project and trying to build a common Resolver to resolve properties of classes at one place For example
public interface MyInterface {
String getSome();
}
public class ClassA implementes MyInterface {
String getSome();
// further props
}
public classB implements MyInterface {
String getSome();
// further props
}
public class MyAweseomeResolver<T extends MyInterface> implements GraphQLResolver<T> {
public String getSomeString(final T concrete) {
return concrete.getSome().toUpperCase()
}
}
Background: I don't want to implement a resolver for each class which are at least doing the same. I just want to have one resolver which applies to all classes implementing one interface.
@matsmad AFAIK there has been no intervention from someone of the team here; so you'll probably have to apply my workaround: https://github.com/graphql-java-kickstart/graphql-java-tools/issues/349#issuecomment-570226121
using this version of the kickstart:
my GraphQL schema:
my Java classes:
Starting my Spring Boot app, I get the following stack trace:
I've seen these (somehow) related issues: https://github.com/graphql-java-kickstart/graphql-java-tools/issues/145 https://github.com/graphql-java-kickstart/graphql-java-tools/issues/163 but with the solution you give in the last comment, I don't understand how I would be able to do something like:
... because that means this resolver is actually a
GraphQLResolver<Bar>
which makes no sense at all (from a Java inheritance scheme point of view)!!Or maybe it's just an erroneous copy/paste from https://github.com/graphql-java-kickstart/graphql-java-tools/issues/331...? (but that's doesn't solve my problem still...)