diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 868756378ef2c..ab07ef6efd5a1 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -47,7 +47,7 @@ 3.3.1 3.0.5 3.1.1 - 1.9.0 + 1.9.1 2.1.1 5.6.0 3.6.0 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 0ac3da55c1ebd..3e8ae58571990 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 @@ -20,6 +20,7 @@ import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; +import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; import org.jboss.jandex.Indexer; @@ -272,8 +273,10 @@ void buildExecutionService( SmallRyeGraphQLRecorder recorder, SmallRyeGraphQLFinalIndexBuildItem graphQLFinalIndexBuildItem, BeanContainerBuildItem beanContainer, + BuildProducer systemPropertyProducer, SmallRyeGraphQLConfig graphQLConfig) { + activateFederation(graphQLConfig, systemPropertyProducer, graphQLFinalIndexBuildItem); Schema schema = SchemaBuilder.build(graphQLFinalIndexBuildItem.getFinalIndex(), graphQLConfig.autoNameStrategy); RuntimeValue initialized = recorder.createExecutionService(beanContainer.getValue(), schema); @@ -627,6 +630,43 @@ void activateEventing(SmallRyeGraphQLConfig graphQLConfig, BuildProducer systemProperties, + SmallRyeGraphQLFinalIndexBuildItem index) { + if (config.federationEnabled.isPresent()) { + String value = config.federationEnabled.get().toString(); + systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_FEDERATION, value)); + System.setProperty(ConfigKey.ENABLE_FEDERATION, value); + } else { + // + boolean foundAnyFederationAnnotation = false; + for (ClassInfo federationAnnotationType : index.getFinalIndex() + .getClassesInPackage("io.smallrye.graphql.api.federation")) { + if (federationAnnotationType.isAnnotation()) { + if (!index.getFinalIndex().getAnnotations(federationAnnotationType.name()).isEmpty()) { + foundAnyFederationAnnotation = true; + } + } + } + String value = Boolean.toString(foundAnyFederationAnnotation); + systemProperties.produce(new SystemPropertyBuildItem(ConfigKey.ENABLE_FEDERATION, value)); + System.setProperty(ConfigKey.ENABLE_FEDERATION, value); + } + } + private boolean shouldActivateService(Optional serviceEnabled, boolean linkedCapabilityIsPresent, String linkedExtensionName, 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/GraphQLFederationDisabledTest.java new file mode 100644 index 0000000000000..8c6e5b49f73ad --- /dev/null +++ b/extensions/smallrye-graphql/deployment/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLFederationDisabledTest.java @@ -0,0 +1,51 @@ +package io.quarkus.smallrye.graphql.deployment; + +import static org.hamcrest.Matchers.*; +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.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; +import io.restassured.RestAssured; + +/** + * Make sure that if no Federation related annotations are in the application, then Federation is + * disabled (unless explicitly enabled in the config). + */ +public class GraphQLFederationDisabledTest extends AbstractGraphQLTest { + + @RegisterExtension + static QuarkusUnitTest test = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses(FooApi.class, Foo.class) + .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); + + @Test + public void checkSchemaDoesNotIncludeServiceDeclaration() { + RestAssured.given() + .get("/graphql/schema.graphql") + .then() + .body(not(containsString("type _Service {"))); + } + + @GraphQLApi + static class FooApi { + + @Query + public Foo foo() { + return new Foo(); + } + + } + + static class Foo { + + public String name; + + } + +} diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfig.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfig.java index fa340d09cf5a2..84a9c90c7ce49 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfig.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLConfig.java @@ -20,6 +20,13 @@ public class SmallRyeGraphQLConfig { @ConfigItem(defaultValue = "graphql") public String rootPath; + /** + * Enable Apollo Federation. If this value is unspecified, then federation will be enabled + * automatically if any GraphQL Federation annotations are detected in the application. + */ + @ConfigItem(name = "federation.enabled") + public Optional federationEnabled; + /** * Enable metrics. By default, this is false. If set to true, a metrics extension is required. */ diff --git a/jakarta/rewrite.yml b/jakarta/rewrite.yml index 6c7d255d15bc6..ec7dfd509d99e 100644 --- a/jakarta/rewrite.yml +++ b/jakarta/rewrite.yml @@ -573,7 +573,7 @@ recipeList: newValue: '6.1.0' - org.openrewrite.maven.ChangePropertyValue: key: smallrye-graphql.version - newValue: '2.0.0' + newValue: '2.0.1' - org.openrewrite.maven.ChangePropertyValue: key: smallrye-health.version newValue: '4.0.1'