Provide more information to TypeResolver#369
Conversation
Allow richer resolution logic
|
@kaqqao Please add the default implementation again: We are on Java 8 now and if that helps not breaking stuff, we will take it. Because changing such a central interface we should avoid almost always, I prefer adding a better alternative side by side. Thanks! |
|
@andimarek The only issue with adding public interface TypeResolver {
default GraphQLObjectType getType(TypeResolutionEnvironment env) { //backward compatible :)
return getType(env.getObject());
}
@Deprecated
GraphQLObjectType getType(Object object); //still forces implementation :(
}Not sure I got you on the last bit, do you mean you'd like me to add the |
|
Sorry to give you a bum steer here. We also have another PR in the works that uses the "parameters pattern". re: #353 I want to get this in place before this PR as the naming of the parameters is preferred. |
|
OK, I'll rework this one then after #353 is merged. Do drop a line if you an opinion on |
|
I think @andimarek wants you to use the default keywords because we can now that we are on Java 8. So yes people will have to implement the old as always but they can opt into the "default" implementation |
|
@kaqqao @bbakerman I would try to avoid such a big breaking change: |
|
@andimarek @bbakerman Here's a suggestion mixing the approaches mentioned so far: public interface TypeResolver {
GraphQLObjectType getType(Object object);
default GraphQLObjectType getType(TypeResolutionEnvironment env) {
return getType(env.getObject());
}
}
public interface AdvancedTypeResolver extends TypeResolver { //could maybe use a better name
@Override
GraphQLObjectType getType(TypeResolutionEnvironment env);
@Override
default GraphQLObjectType getType(Object object) {
//Could instead delegate to the method above, but I think an exception is better as library code never actually calls this method
throw new UnsupportedOperationException("AdvancedTypeResolver does not support simple type resolution");
}
}While a bit convoluted, this solves the conundrum rather effectively. Didn't want to push it like this before I hear your comments. |
|
@kaqqao Thanks ... this goes in the direction I would prefer. But do we need the new method in |
|
@andimarek It is confusing, I agree. I added it to remove the need for any other changes. If I remove it, I have 2 options:
typeResolver instanceof AdvancedTypeResolver ? ((AdvancedTypeResolver) typeResolver).getType(env) : typeResolver.getType(env.getObject);
Do you think one of these is the way to go? |
| return result; | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
We already broke this SPI in 3.0 with the earlier "parameters" change. You dont need to to this.
|
I think I will close this one and use the other one (which is essentially yours) as the way forward |
|
Awesome! Do you need me to do anything at this point? |
|
Now merged |
closes #122
(I closed my original PR #343 because I managed to get myself in a Git situation that was easier for me to resolve by recreating the branch, thus opening a new PR)
I've reimplemented the changes to the
ExecutionStrategyin a way that allows easier future modifications, and made overloads and deprecations for backward-compatibility.Implementation notes:
...Parametersclasses where I needed them for this change, not everywhere where they should arguably go. Tell me If you want me refactor more places....Parametersconstructors private to avoid implementors relying on them and ending up in this same situation. I wanted them package private so that they can be used internally, butBatchedExecutionStrategyis in a different package so there wasn't much point.@Deprecatedmethods only to link to the new options, but since this is not a full Javadoc, a lot of lint warnings are generated during the build. Would you rather have the incomplete docs removed or maybe provide the text you'd like in the Javadoc, or would you like me to add my own?Now, the question comes back to the
TypeResolver:defaultfor backwards compatibilityOne idea I have is to introduce a new interface, e.g.
TypeDecider, that would provide the new functionality:GraphQLObjectType getType(TypeResolutionEnvironment env), and then change the builders that acceptTypeResolvers in a fashion similar to this:With both approaches, backwards-compatibility would be, I think, complete.
I've already implemented the
TypeDeciderapproach, so if you like that option I can push it for review.