diff --git a/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/DynamicGraphQLClientMissingUrlTest.java b/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/DynamicGraphQLClientMissingUrlTest.java deleted file mode 100644 index c0eb75ccd635ec..00000000000000 --- a/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/DynamicGraphQLClientMissingUrlTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.quarkus.smallrye.graphql.client.deployment; - -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - -import javax.enterprise.inject.Instance; -import javax.inject.Inject; - -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.test.QuarkusUnitTest; -import io.smallrye.graphql.client.GraphQLClient; -import io.smallrye.graphql.client.dynamic.api.DynamicGraphQLClient; - -public class DynamicGraphQLClientMissingUrlTest { - - @RegisterExtension - static QuarkusUnitTest test = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); - - @Inject - @GraphQLClient("invalid") - Instance client; - - /** - * Check that when URL is not defined for a dynamic client, the thrown error message suggests the - * `quarkus.*` config property rather than the SmallRye property (`CLIENT_NAME/mp-graphql/url`). This - * is achieved by using `io.quarkus.smallrye.graphql.client.runtime.QuarkifiedErrorMessageProvider`. - */ - @Test - public void checkErrorMessage() { - try { - client.get(); - fail("Injection of a dynamic client must fail because no URL is defined"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("quarkus.smallrye-graphql-client.invalid.url")); - } - } - -} diff --git a/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/TypesafeGraphQLClientMissingUrlTest.java b/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/TypesafeGraphQLClientMissingUrlTest.java deleted file mode 100644 index c241d27f5c2c81..00000000000000 --- a/extensions/smallrye-graphql-client/deployment/src/test/java/io/quarkus/smallrye/graphql/client/deployment/TypesafeGraphQLClientMissingUrlTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.quarkus.smallrye.graphql.client.deployment; - -import static org.junit.jupiter.api.Assertions.*; - -import javax.enterprise.inject.Instance; -import javax.inject.Inject; - -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.smallrye.graphql.client.deployment.model.Person; -import io.quarkus.smallrye.graphql.client.deployment.model.TestingGraphQLApi; -import io.quarkus.smallrye.graphql.client.deployment.model.TestingGraphQLClientApi; -import io.quarkus.test.QuarkusUnitTest; - -public class TypesafeGraphQLClientMissingUrlTest { - - @RegisterExtension - static QuarkusUnitTest test = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addClasses(TestingGraphQLApi.class, TestingGraphQLClientApi.class, Person.class) - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); - - @Inject - Instance client; - - /** - * Check that when URL is not defined for a typesafe client, the thrown error message suggests the - * `quarkus.*` config property rather than the SmallRye property (`CLIENT_NAME/mp-graphql/url`). This - * is achieved by using `io.quarkus.smallrye.graphql.client.runtime.QuarkifiedErrorMessageProvider`. - */ - @Test - public void checkErrorMessage() { - try { - client.get(); - fail("Injection of a typesafe client must fail because no URL is defined"); - } catch (RuntimeException e) { - assertTrue(e.getMessage().contains("quarkus.smallrye-graphql-client.typesafeclient.url")); - } - } - -} diff --git a/integration-tests/smallrye-graphql-client/src/main/java/io/quarkus/io/smallrye/graphql/client/GraphQLClientTester.java b/integration-tests/smallrye-graphql-client/src/main/java/io/quarkus/io/smallrye/graphql/client/GraphQLClientTester.java index 7e099d4aff2b88..5b8282503c3392 100644 --- a/integration-tests/smallrye-graphql-client/src/main/java/io/quarkus/io/smallrye/graphql/client/GraphQLClientTester.java +++ b/integration-tests/smallrye-graphql-client/src/main/java/io/quarkus/io/smallrye/graphql/client/GraphQLClientTester.java @@ -10,10 +10,12 @@ import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; +import javax.inject.Inject; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import io.smallrye.graphql.client.GraphQLClient; import io.smallrye.graphql.client.Response; import io.smallrye.graphql.client.core.Document; import io.smallrye.graphql.client.core.OperationType; @@ -148,4 +150,22 @@ public void dynamicSubscription(@PathParam("url") String url) throws Exception { } } + @GraphQLClient("some-key") + DynamicGraphQLClient autowiredDynamicClient; + + @GET + @Path("/autowired-dynamic") + public void autowiredDynamicClient() throws ExecutionException, InterruptedException { + testSingleResultOperationsWithDynamicClient(autowiredDynamicClient); + } + + @Inject + LuckyNumbersClientApi autowiredTypesafeClient; + + @GET + @Path("/autowired-typesafe") + public void autowiredTypesafeClient() throws Exception { + testSingleResultOperationsWithTypesafeClient(autowiredTypesafeClient); + } + } diff --git a/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/DynamicClientTest.java b/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/DynamicClientTest.java index 24d86f42cc070a..76de197616e3c1 100644 --- a/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/DynamicClientTest.java +++ b/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/DynamicClientTest.java @@ -45,4 +45,13 @@ public void testDynamicClientSubscription() throws Exception { .statusCode(204); } + @Test + public void testDynamicClientAutowiredUrl() throws Exception { + when() + .get("/autowired-dynamic/") + .then() + .log().everything() + .statusCode(204); + } + } diff --git a/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/TypesafeClientTest.java b/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/TypesafeClientTest.java index 601420b62e26d2..f25336039e7e53 100644 --- a/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/TypesafeClientTest.java +++ b/integration-tests/smallrye-graphql-client/src/test/java/io/quarkus/it/smallrye/graphql/client/TypesafeClientTest.java @@ -60,4 +60,13 @@ public void testHeader() { .statusCode(204); } + @Test + public void testAutowiredUrl() throws Exception { + when() + .get("/autowired-typesafe/") + .then() + .log().everything() + .statusCode(204); + } + }