From 5f0502277296e2f8b4d0fd8cc195ac59a8c980fa Mon Sep 17 00:00:00 2001 From: Jan Martiska Date: Fri, 8 Jul 2022 10:31:50 +0200 Subject: [PATCH] Properly resolve enum in a field with type variable --- .../impl/typesafe/reflection/TypeInfo.java | 7 +++- .../tck/graphql/typesafe/EnumBehavior.java | 42 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/client/implementation/src/main/java/io/smallrye/graphql/client/impl/typesafe/reflection/TypeInfo.java b/client/implementation/src/main/java/io/smallrye/graphql/client/impl/typesafe/reflection/TypeInfo.java index a69d71e39..1492ab2e9 100644 --- a/client/implementation/src/main/java/io/smallrye/graphql/client/impl/typesafe/reflection/TypeInfo.java +++ b/client/implementation/src/main/java/io/smallrye/graphql/client/impl/typesafe/reflection/TypeInfo.java @@ -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 scalarConstructor() { diff --git a/client/tck/src/main/java/tck/graphql/typesafe/EnumBehavior.java b/client/tck/src/main/java/tck/graphql/typesafe/EnumBehavior.java index cc66e901e..5da2dda8f 100644 --- a/client/tck/src/main/java/tck/graphql/typesafe/EnumBehavior.java +++ b/client/tck/src/main/java/tck/graphql/typesafe/EnumBehavior.java @@ -14,6 +14,31 @@ class EnumBehavior { private final TypesafeGraphQLClientFixture fixture = TypesafeGraphQLClientFixture.load(); + public static class DescribedValue { + + 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, @@ -68,4 +93,21 @@ void shouldCallEnumFilterQuery() { then(fixture.variables()).isEqualTo("{'episode':'JEDI'}"); then(characters).containsExactly("Luke", "Darth"); } + + @GraphQLClientApi + interface EpisodeGenericApi { + DescribedValue describedEpisode(); + } + + @Test + void shouldCallGenericQuery() { + fixture.returnsData("'describedEpisode':{'value':'NEWHOPE','description':'Episode 4'}"); + EpisodeGenericApi api = fixture.build(EpisodeGenericApi.class); + + DescribedValue episode = api.describedEpisode(); + + then(fixture.query()).isEqualTo("query describedEpisode { describedEpisode {value description} }"); + then(episode.description).isEqualTo("Episode 4"); + then(episode.value).isEqualTo(NEWHOPE); + } }