diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationTest.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationTest.java deleted file mode 100644 index 82d7414e50ff6..0000000000000 --- a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.quarkus.smallrye.graphql.deployment; - -import static org.hamcrest.Matchers.containsString; - -import org.eclipse.microprofile.graphql.GraphQLApi; -import org.eclipse.microprofile.graphql.Query; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.asset.StringAsset; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import io.quarkus.test.QuarkusUnitTest; -import io.restassured.RestAssured; -import io.smallrye.graphql.api.federation.External; - -public class GraphQLFederationTest extends AbstractGraphQLTest { - - @RegisterExtension - static QuarkusUnitTest test = new QuarkusUnitTest() - .withApplicationRoot((jar) -> jar - .addClasses(FooApi.class, Foo.class) - .addAsResource(new StringAsset("quarkus.smallrye-graphql.schema-include-directives=true"), - "application.properties") - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); - - @Test - public void checkServiceDeclarationInSchema() { - RestAssured.given() - .get("/graphql/schema.graphql") - .then() - .body(containsString("type _Service {")); - } - - @Test - public void checkFederationDirectivesInSchema() { - RestAssured.given() - .get("/graphql/schema.graphql") - .then() - .body(containsString("name: String @external")); - } - - @GraphQLApi - static class FooApi { - - @Query - public Foo foo() { - return new Foo(); - } - - } - - static class Foo { - - @External - public String name; - - } - -} diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationDisabledTest.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/GraphQLFederationDisabledTest.java similarity index 91% rename from extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationDisabledTest.java rename to extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/GraphQLFederationDisabledTest.java index 8c6e5b49f73ad..09eb31fe450e6 100644 --- a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationDisabledTest.java +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/GraphQLFederationDisabledTest.java @@ -1,4 +1,4 @@ -package io.quarkus.smallrye.graphql.deployment; +package io.quarkus.smallrye.graphql.deployment.federation; import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.containsString; @@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest; import io.quarkus.test.QuarkusUnitTest; import io.restassured.RestAssured; diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/Foo.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/Foo.java new file mode 100644 index 0000000000000..24b579afa4eaa --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/Foo.java @@ -0,0 +1,16 @@ +package io.quarkus.smallrye.graphql.deployment.federation.base; + +import io.smallrye.graphql.api.federation.Extends; +import io.smallrye.graphql.api.federation.External; +import io.smallrye.graphql.api.federation.Key; + +@Key(fields = "id") +@Extends +public class Foo { + + @External + public int id; + + public String name; + +} diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/FooApi.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/FooApi.java new file mode 100644 index 0000000000000..7da8d3a68112c --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/FooApi.java @@ -0,0 +1,15 @@ +package io.quarkus.smallrye.graphql.deployment.federation.base; + +import org.eclipse.microprofile.graphql.GraphQLApi; +import org.eclipse.microprofile.graphql.Query; + +@GraphQLApi +public class FooApi { + @Query + public Foo foo(int id) { + var foo = new Foo(); + foo.id = id; + foo.name = "Name of " + id; + return foo; + } +} diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/GraphQLFederationBaseTest.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/GraphQLFederationBaseTest.java new file mode 100644 index 0000000000000..44ede12ca5c37 --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/GraphQLFederationBaseTest.java @@ -0,0 +1,79 @@ +package io.quarkus.smallrye.graphql.deployment.federation.base; + +import static org.hamcrest.Matchers.containsString; + +import org.hamcrest.CoreMatchers; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest; +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class GraphQLFederationBaseTest extends AbstractGraphQLTest { + + @RegisterExtension + static QuarkusUnitTest test = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(FooApi.class, Foo.class) + .addAsResource(new StringAsset("quarkus.smallrye-graphql.schema-include-directives=true"), + "application.properties") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); + + @Test + public void checkServiceDeclarationInSchema() { + RestAssured.given() + .get("/graphql/schema.graphql") + .then() + .body(containsString("type _Service {")); + } + + @Test + public void checkFederationDirectivesInSchema() { + RestAssured.given() + .get("/graphql/schema.graphql") + .then() + .body(containsString("id: Int! @external")) + .body(containsString("type Foo @extends @key(fields : \"id\")")); + ; + } + + @Test + public void resolvePerFederation() { + String query = "query federation($representations: [_Any!]!) {\n" + + " _entities(representations: $representations) {\n" + + " ... on Foo {\n" + + " id\n" + + " name\n" + + " }\n" + + " }\n" + + "}"; + String variables = "{\n" + + " \"representations\": [\n" + + " {\n" + + " \"__typename\": \"Foo\",\n" + + " \"id\": 1\n" + + " },\n" + + " {\n" + + " \"__typename\": \"Foo\",\n" + + " \"id\": 2\n" + + " }\n" + + " ]\n" + + "}"; + + String request = getPayload(query, variables); + RestAssured.given().when() + .accept(MEDIATYPE_JSON) + .contentType(MEDIATYPE_JSON) + .body(request) + .post("/graphql") + .then() + .assertThat() + .statusCode(200) + .and() + .body(CoreMatchers.is( + "{\"data\":{\"_entities\":[{\"id\":1,\"name\":\"Name of 1\"},{\"id\":2,\"name\":\"Name of 2\"}]}}")); + } +} diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/uni/FooApiUni.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/uni/FooApiUni.java new file mode 100644 index 0000000000000..a3059e86cfd67 --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/uni/FooApiUni.java @@ -0,0 +1,18 @@ +package io.quarkus.smallrye.graphql.deployment.federation.base.uni; + +import org.eclipse.microprofile.graphql.GraphQLApi; +import org.eclipse.microprofile.graphql.Query; + +import io.quarkus.smallrye.graphql.deployment.federation.base.Foo; +import io.smallrye.mutiny.Uni; + +@GraphQLApi +public class FooApiUni { + @Query + public Uni foo(int id) { + var foo = new Foo(); + foo.id = id; + foo.name = "Name of " + id; + return Uni.createFrom().item(foo); + } +} diff --git a/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/uni/GraphQLFederationBaseUniTest.java b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/uni/GraphQLFederationBaseUniTest.java new file mode 100644 index 0000000000000..c65fd8fde77ed --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/federation/base/uni/GraphQLFederationBaseUniTest.java @@ -0,0 +1,80 @@ +package io.quarkus.smallrye.graphql.deployment.federation.base.uni; + +import static org.hamcrest.Matchers.containsString; + +import org.hamcrest.CoreMatchers; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest; +import io.quarkus.smallrye.graphql.deployment.federation.base.Foo; +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +public class GraphQLFederationBaseUniTest extends AbstractGraphQLTest { + + @RegisterExtension + static QuarkusUnitTest test = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(FooApiUni.class, Foo.class) + .addAsResource(new StringAsset("quarkus.smallrye-graphql.schema-include-directives=true"), + "application.properties") + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); + + @Test + public void checkServiceDeclarationInSchema() { + RestAssured.given() + .get("/graphql/schema.graphql") + .then() + .body(containsString("type _Service {")); + } + + @Test + public void checkFederationDirectivesInSchema() { + RestAssured.given() + .get("/graphql/schema.graphql") + .then() + .body(containsString("id: Int! @external")) + .body(containsString("type Foo @extends @key(fields : \"id\")")); + ; + } + + @Test + public void resolvePerFederation() { + String query = "query federation($representations: [_Any!]!) {\n" + + " _entities(representations: $representations) {\n" + + " ... on Foo {\n" + + " id\n" + + " name\n" + + " }\n" + + " }\n" + + "}"; + String variables = "{\n" + + " \"representations\": [\n" + + " {\n" + + " \"__typename\": \"Foo\",\n" + + " \"id\": 1\n" + + " },\n" + + " {\n" + + " \"__typename\": \"Foo\",\n" + + " \"id\": 2\n" + + " }\n" + + " ]\n" + + "}"; + + String request = getPayload(query, variables); + RestAssured.given().when() + .accept(MEDIATYPE_JSON) + .contentType(MEDIATYPE_JSON) + .body(request) + .post("/graphql") + .then() + .assertThat() + .statusCode(200) + .and() + .body(CoreMatchers.is( + "{\"data\":{\"_entities\":[{\"id\":1,\"name\":\"Name of 1\"},{\"id\":2,\"name\":\"Name of 2\"}]}}")); + } +}