diff --git a/client/implementation/src/main/java/io/smallrye/graphql/client/typesafe/impl/reflection/MethodInvocation.java b/client/implementation/src/main/java/io/smallrye/graphql/client/typesafe/impl/reflection/MethodInvocation.java index 30a3d7ab5..2b77a8470 100644 --- a/client/implementation/src/main/java/io/smallrye/graphql/client/typesafe/impl/reflection/MethodInvocation.java +++ b/client/implementation/src/main/java/io/smallrye/graphql/client/typesafe/impl/reflection/MethodInvocation.java @@ -18,10 +18,10 @@ import javax.enterprise.inject.Stereotype; import org.eclipse.microprofile.graphql.Mutation; +import org.eclipse.microprofile.graphql.Name; import org.eclipse.microprofile.graphql.Query; import io.smallrye.graphql.client.typesafe.api.GraphQlClientException; -import io.smallrye.graphql.client.typesafe.impl.CollectionUtils; public class MethodInvocation { public static MethodInvocation of(Method method, Object... args) { @@ -48,7 +48,7 @@ public String getKey() { } public boolean isQuery() { - return !ifAnnotated(Mutation.class).isPresent(); + return !method.isAnnotationPresent(Mutation.class); } public String getName() { @@ -58,15 +58,20 @@ public String getName() { } private Optional queryName() { - return ifAnnotated(Query.class) - .map(Query::value) - .filter(CollectionUtils::nonEmpty); + Query query = method.getAnnotation(Query.class); + if (query != null && !query.value().isEmpty()) + return Optional.of(query.value()); + Name name = method.getAnnotation(Name.class); + if (name != null) + return Optional.of(name.value()); + return Optional.empty(); } private Optional mutationName() { - return ifAnnotated(Mutation.class) - .map(Mutation::value) - .filter(CollectionUtils::nonEmpty); + Mutation mutation = method.getAnnotation(Mutation.class); + if (mutation != null && !mutation.value().isEmpty()) + return Optional.of(mutation.value()); + return Optional.empty(); } private String methodName() { @@ -76,10 +81,6 @@ private String methodName() { return name; } - private Optional ifAnnotated(Class type) { - return Optional.ofNullable(method.getAnnotation(type)); - } - public TypeInfo getReturnType() { return new TypeInfo(type, method.getGenericReturnType(), method.getAnnotatedReturnType()); } diff --git a/client/implementation/src/test/java/test/unit/AnnotationBehavior.java b/client/implementation/src/test/java/test/unit/AnnotationBehavior.java index c8e4c88a8..8398c8717 100644 --- a/client/implementation/src/test/java/test/unit/AnnotationBehavior.java +++ b/client/implementation/src/test/java/test/unit/AnnotationBehavior.java @@ -47,6 +47,24 @@ void shouldCallParamQuery() { then(greeting).isEqualTo("hi, foo"); } + @GraphQlClientApi + interface RenamedMethodApi { + @Name("greeting") + String someOtherMethodName(); + } + + @Test + void shouldCallRenamedQuery() { + fixture.returnsData("'greeting':'hi, foo'"); + RenamedMethodApi api = fixture.build(RenamedMethodApi.class); + + String greeting = api.someOtherMethodName(); + + then(fixture.query()).isEqualTo("query greeting { greeting }"); + then(fixture.variables()).isEqualTo("{}"); + then(greeting).isEqualTo("hi, foo"); + } + @GraphQlClientApi interface ObjectApi { Greeting greeting(); diff --git a/client/implementation/src/test/java/test/unit/ErrorBehavior.java b/client/implementation/src/test/java/test/unit/ErrorBehavior.java index 6fb677beb..a4e6c0e80 100644 --- a/client/implementation/src/test/java/test/unit/ErrorBehavior.java +++ b/client/implementation/src/test/java/test/unit/ErrorBehavior.java @@ -244,7 +244,6 @@ static class Team { @GraphQlClientApi interface SuperHeroApi { - @Name("findTeams") ErrorOr> teams(); } diff --git a/client/implementation/src/test/java/test/unit/ParametersBehavior.java b/client/implementation/src/test/java/test/unit/ParametersBehavior.java index 9d65da18a..3fb4978d5 100644 --- a/client/implementation/src/test/java/test/unit/ParametersBehavior.java +++ b/client/implementation/src/test/java/test/unit/ParametersBehavior.java @@ -57,24 +57,6 @@ void shouldCallNonNullStringParamQuery() { then(greeting).isEqualTo("hi, foo"); } - @GraphQlClientApi - interface RenamedParamApi { - String greeting(@Name("who") String foo); - } - - @Test - void shouldCallRenamedParamQuery() { - fixture.returnsData("'greeting':'hi, foo'"); - RenamedParamApi api = fixture.build(RenamedParamApi.class); - - String greeting = api.greeting("foo"); - - then(fixture.query()).isEqualTo("query greeting($who: String) { greeting(who: $who) }"); - then(fixture.variables()).isEqualTo("{'who':'foo'}"); - then(fixture.operationName()).isEqualTo("greeting"); - then(greeting).isEqualTo("hi, foo"); - } - @Test void shouldEscapeParamScalarQuery() { fixture.returnsData("'greeting':'hi, foo'"); diff --git a/pom.xml b/pom.xml index 65b396fea..fbdc4ed0e 100644 --- a/pom.xml +++ b/pom.xml @@ -309,6 +309,7 @@ false true false + -DskipTests ${release.arguments}