From 7ba35215b86569ccf3f8ea5f19f966d0d4cf1860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vav=C5=99=C3=ADk?= Date: Fri, 9 Feb 2024 14:44:19 +0100 Subject: [PATCH] Avoid Vert.x GraphQL deprecation warning --- .../deployment/VertxGraphqlProcessor.java | 24 +++++++++++++------ .../graphql/runtime/VertxGraphqlRecorder.java | 6 +++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/extensions/vertx-graphql/deployment/src/main/java/io/quarkus/vertx/graphql/deployment/VertxGraphqlProcessor.java b/extensions/vertx-graphql/deployment/src/main/java/io/quarkus/vertx/graphql/deployment/VertxGraphqlProcessor.java index 894c352ef7b33..4a33ea01ca16f 100644 --- a/extensions/vertx-graphql/deployment/src/main/java/io/quarkus/vertx/graphql/deployment/VertxGraphqlProcessor.java +++ b/extensions/vertx-graphql/deployment/src/main/java/io/quarkus/vertx/graphql/deployment/VertxGraphqlProcessor.java @@ -14,6 +14,7 @@ import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.builditem.nativeimage.*; import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.vertx.core.deployment.CoreVertxBuildItem; import io.quarkus.vertx.graphql.runtime.VertxGraphqlRecorder; import io.quarkus.vertx.http.deployment.BodyHandlerBuildItem; import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem; @@ -57,17 +58,24 @@ void registerI18nResources(BuildProducer res resourceBundle.produce(new NativeImageResourceBundleBuildItem("i18n/Validation")); } + @BuildStep + NativeImageResourceDirectoryBuildItem produceNativeResourceDirectory(LaunchModeBuildItem launchMode, + VertxGraphqlConfig config) { + if (doNotIncludeVertxGraphqlUi(launchMode, config)) { + return null; + } + return new NativeImageResourceDirectoryBuildItem("io/vertx/ext/web/handler/graphiql"); + } + @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - void registerVertxGraphqlUI(VertxGraphqlRecorder recorder, - BuildProducer nativeResourcesProducer, VertxGraphqlConfig config, - LaunchModeBuildItem launchMode, + void registerVertxGraphqlUI(VertxGraphqlRecorder recorder, VertxGraphqlConfig config, + LaunchModeBuildItem launchMode, CoreVertxBuildItem coreVertxBuildItem, NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, BuildProducer routes, BodyHandlerBuildItem bodyHandler) { - boolean includeVertxGraphqlUi = launchMode.getLaunchMode().isDevOrTest() || config.ui.alwaysInclude; - if (!includeVertxGraphqlUi) { + if (doNotIncludeVertxGraphqlUi(launchMode, config)) { return; } @@ -79,7 +87,7 @@ void registerVertxGraphqlUI(VertxGraphqlRecorder recorder, + "\", this is not allowed as it blocks the application from serving anything else."); } - Handler handler = recorder.handler(); + Handler handler = recorder.handler(coreVertxBuildItem.getVertx()); routes.produce(nonApplicationRootPathBuildItem.routeBuilder() .route(path) .handler(handler) @@ -90,7 +98,9 @@ void registerVertxGraphqlUI(VertxGraphqlRecorder recorder, .routeFunction(path + "/*", recorder.routeFunction(bodyHandler.getHandler())) .handler(handler) .build()); + } - nativeResourcesProducer.produce(new NativeImageResourceDirectoryBuildItem("io/vertx/ext/web/handler/graphiql")); + private static boolean doNotIncludeVertxGraphqlUi(LaunchModeBuildItem launchMode, VertxGraphqlConfig config) { + return !launchMode.getLaunchMode().isDevOrTest() && !config.ui.alwaysInclude; } } diff --git a/extensions/vertx-graphql/runtime/src/main/java/io/quarkus/vertx/graphql/runtime/VertxGraphqlRecorder.java b/extensions/vertx-graphql/runtime/src/main/java/io/quarkus/vertx/graphql/runtime/VertxGraphqlRecorder.java index 7ca208a914672..cf72b8c02df9b 100644 --- a/extensions/vertx-graphql/runtime/src/main/java/io/quarkus/vertx/graphql/runtime/VertxGraphqlRecorder.java +++ b/extensions/vertx-graphql/runtime/src/main/java/io/quarkus/vertx/graphql/runtime/VertxGraphqlRecorder.java @@ -1,9 +1,11 @@ package io.quarkus.vertx.graphql.runtime; import java.util.function.Consumer; +import java.util.function.Supplier; import io.quarkus.runtime.annotations.Recorder; import io.vertx.core.Handler; +import io.vertx.core.Vertx; import io.vertx.core.http.HttpHeaders; import io.vertx.ext.web.Route; import io.vertx.ext.web.RoutingContext; @@ -12,12 +14,12 @@ @Recorder public class VertxGraphqlRecorder { - public Handler handler() { + public Handler handler(Supplier vertx) { GraphiQLHandlerOptions options = new GraphiQLHandlerOptions(); options.setEnabled(true); - Handler handler = GraphiQLHandler.create(options); + Handler handler = GraphiQLHandler.create(vertx.get(), options); return new Handler() { @Override