Allow using a sub-interface of a generic interface as API with Typesafe client #2151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
I want to be able to write a GraphQL api and provide a Java interface for my clients, whilst keeping GraphQL strength of allowing clients to choose exactly what data they will receive. For that, we could use generics.
So, as the writer of the GraphQL endpoint, I would for example give this to my clients:
T
could be for example:public record MyItemSimple(String name) {}
orpublic record MyItemFull(String name, String extraLongDescription) {}
Then, on the client side, I would be able to choose between:
or
depending on the data needed, and
getItem()
would return exactly that.Problem
That fails with:
The only way to get it working is to explicitly override the generic method.
Solution
This PR provides a way to fix this and makes the scenario described here as expected.