Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly resolve enum in a field with type variable #1466

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ public boolean isPrimitive() {
}

public boolean isEnum() {
return ifClass(Class::isEnum);
if (type instanceof TypeVariable) {
Class<?> resolved = resolveTypeVariable();
return resolved.isEnum();
} else {
return ifClass(Class::isEnum);
}
}

public Optional<ConstructionInfo> scalarConstructor() {
Expand Down
42 changes: 42 additions & 0 deletions client/tck/src/main/java/tck/graphql/typesafe/EnumBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@
class EnumBehavior {
private final TypesafeGraphQLClientFixture fixture = TypesafeGraphQLClientFixture.load();

public static class DescribedValue<T> {

public DescribedValue() {
}

T value;
String description;

public T getValue() {
return value;
}

public void setValue(T value) {
this.value = value;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}

enum Episode {
NEWHOPE,
EMPIRE,
Expand Down Expand Up @@ -68,4 +93,21 @@ void shouldCallEnumFilterQuery() {
then(fixture.variables()).isEqualTo("{'episode':'JEDI'}");
then(characters).containsExactly("Luke", "Darth");
}

@GraphQLClientApi
interface EpisodeGenericApi {
DescribedValue<Episode> describedEpisode();
}

@Test
void shouldCallGenericQuery() {
fixture.returnsData("'describedEpisode':{'value':'NEWHOPE','description':'Episode 4'}");
EpisodeGenericApi api = fixture.build(EpisodeGenericApi.class);

DescribedValue<Episode> episode = api.describedEpisode();

then(fixture.query()).isEqualTo("query describedEpisode { describedEpisode {value description} }");
then(episode.description).isEqualTo("Episode 4");
then(episode.value).isEqualTo(NEWHOPE);
}
}