Skip to content

Commit

Permalink
Merge pull request #1466 from jmartisk/1.6.x-issue-1465
Browse files Browse the repository at this point in the history
Properly resolve enum in a field with type variable
  • Loading branch information
phillip-kruger authored Jul 20, 2022
2 parents 94164da + 5f05022 commit 63cd344
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
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);
}
}

0 comments on commit 63cd344

Please sign in to comment.