Skip to content

Commit

Permalink
Merge pull request quarkusio#38710 from michalvavrik/feature/avoid-ve…
Browse files Browse the repository at this point in the history
…rtx-graphql-deprecation-warning

Avoid Vert.x GraphQL deprecation warning
  • Loading branch information
gsmet authored Feb 10, 2024
2 parents 40b20b8 + 7ba3521 commit d9cd57a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,17 +58,24 @@ void registerI18nResources(BuildProducer<NativeImageResourceBundleBuildItem> 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<NativeImageResourceDirectoryBuildItem> nativeResourcesProducer, VertxGraphqlConfig config,
LaunchModeBuildItem launchMode,
void registerVertxGraphqlUI(VertxGraphqlRecorder recorder, VertxGraphqlConfig config,
LaunchModeBuildItem launchMode, CoreVertxBuildItem coreVertxBuildItem,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
BuildProducer<RouteBuildItem> routes,
BodyHandlerBuildItem bodyHandler) {

boolean includeVertxGraphqlUi = launchMode.getLaunchMode().isDevOrTest() || config.ui.alwaysInclude;
if (!includeVertxGraphqlUi) {
if (doNotIncludeVertxGraphqlUi(launchMode, config)) {
return;
}

Expand All @@ -79,7 +87,7 @@ void registerVertxGraphqlUI(VertxGraphqlRecorder recorder,
+ "\", this is not allowed as it blocks the application from serving anything else.");
}

Handler<RoutingContext> handler = recorder.handler();
Handler<RoutingContext> handler = recorder.handler(coreVertxBuildItem.getVertx());
routes.produce(nonApplicationRootPathBuildItem.routeBuilder()
.route(path)
.handler(handler)
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,12 +14,12 @@

@Recorder
public class VertxGraphqlRecorder {
public Handler<RoutingContext> handler() {
public Handler<RoutingContext> handler(Supplier<Vertx> vertx) {

GraphiQLHandlerOptions options = new GraphiQLHandlerOptions();
options.setEnabled(true);

Handler<RoutingContext> handler = GraphiQLHandler.create(options);
Handler<RoutingContext> handler = GraphiQLHandler.create(vertx.get(), options);

return new Handler<RoutingContext>() {
@Override
Expand Down

0 comments on commit d9cd57a

Please sign in to comment.