Skip to content

Commit

Permalink
fix(vertx-graphql): make the extension work in native mode
Browse files Browse the repository at this point in the history
fixes #5248
  • Loading branch information
machi1990 committed Nov 12, 2019
1 parent c499346 commit 428851a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion ci-templates/stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,12 @@ stages:
parameters:
poolSettings: ${{parameters.poolSettings}}
expectUseVMs: ${{parameters.expectUseVMs}}
timeoutInMinutes: 25
timeoutInMinutes: 30
modules:
- resteasy-jackson
- vertx
- vertx-http
- vertx-graphql
- virtual-http
name: http

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package io.quarkus.vertx.graphql.deployment;

import java.util.Arrays;
import java.util.List;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImagePackageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.vertx.http.deployment.WebsocketSubProtocolsBuildItem;
import io.vertx.ext.web.handler.graphql.impl.GraphQLBatch;
import io.vertx.ext.web.handler.graphql.impl.GraphQLInputDeserializer;
import io.vertx.ext.web.handler.graphql.impl.GraphQLQuery;

class VertxGraphqlProcessor {

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FeatureBuildItem.VERTX_GRAPHQL);
Expand All @@ -15,4 +22,17 @@ FeatureBuildItem feature() {
WebsocketSubProtocolsBuildItem websocketSubProtocols() {
return new WebsocketSubProtocolsBuildItem("graphql-ws");
}

@BuildStep
List<ReflectiveClassBuildItem> registerForReflection() {
return Arrays.asList(
new ReflectiveClassBuildItem(true, true, GraphQLInputDeserializer.class.getName()),
new ReflectiveClassBuildItem(true, true, GraphQLBatch.class.getName()),
new ReflectiveClassBuildItem(true, true, GraphQLQuery.class.getName()));
}

@BuildStep
NativeImagePackageResourceBuildItem registerNativeImageResources() {
return new NativeImagePackageResourceBuildItem("io/vertx/ext/web/handler/graphiql");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -20,10 +18,6 @@

@QuarkusTest
class VertxGraphqlTest {

@Inject
Vertx vertx;

public static int getPortFromConfig() {
return ConfigProvider.getConfig().getOptionalValue("quarkus.http.test-port", Integer.class).orElse(8081);
}
Expand All @@ -37,12 +31,14 @@ public void testGraphQlQuery() {

@Test
public void testWebSocketSubProtocol() throws Exception {
Vertx vertx = Vertx.vertx();
HttpClient httpClient = vertx.createHttpClient();
WebSocketConnectOptions options = new WebSocketConnectOptions().setPort(getPortFromConfig())
.addSubProtocol("graphql-ws").setURI("/graphql");
CompletableFuture<Boolean> wsFuture = new CompletableFuture<>();
httpClient.webSocket(options, event -> wsFuture.complete(event.succeeded()));
Assertions.assertTrue(wsFuture.get(1, TimeUnit.MINUTES));
vertx.close();
}

}

0 comments on commit 428851a

Please sign in to comment.