From b6eeaa0290dd71d6424b2772ed887253a32fcfed Mon Sep 17 00:00:00 2001 From: Jan Martiska Date: Tue, 3 Jan 2023 12:18:38 +0100 Subject: [PATCH] Make sure Federation annotations are in the index, add a test (cherry picked from commit 7d129dd72c27954eb5974d08b4fb0c642f2f5e34) --- .../deployment/SmallRyeGraphQLProcessor.java | 10 ++++ .../deployment/GraphQLFederationTest.java | 59 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationTest.java diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java index e6e11bc9419e8..0ac3da55c1ebd 100644 --- a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java @@ -71,6 +71,11 @@ import io.smallrye.graphql.api.AdaptWith; import io.smallrye.graphql.api.Entry; import io.smallrye.graphql.api.ErrorExtensionProvider; +import io.smallrye.graphql.api.federation.Extends; +import io.smallrye.graphql.api.federation.External; +import io.smallrye.graphql.api.federation.Key; +import io.smallrye.graphql.api.federation.Provides; +import io.smallrye.graphql.api.federation.Requires; import io.smallrye.graphql.cdi.config.ConfigKey; import io.smallrye.graphql.cdi.config.MicroProfileConfig; import io.smallrye.graphql.cdi.producer.GraphQLProducer; @@ -244,6 +249,11 @@ void buildFinalIndex( try { indexer.indexClass(Map.class); indexer.indexClass(Entry.class); + indexer.indexClass(Extends.class); + indexer.indexClass(External.class); + indexer.indexClass(Key.class); + indexer.indexClass(Provides.class); + indexer.indexClass(Requires.class); } catch (IOException ex) { LOG.warn("Failure while creating index", ex); } 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 new file mode 100644 index 0000000000000..587f597fea5a8 --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationTest.java @@ -0,0 +1,59 @@ +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.Extends; + +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 @extends")); + } + + @GraphQLApi + static class FooApi { + + @Query + public Foo foo() { + return new Foo(); + } + + } + + static class Foo { + + @Extends + public String name; + + } + +}