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 5a6ac7c commit 3fd3ce8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
19 changes: 10 additions & 9 deletions ci-templates/stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ stages:
jobs:
- job: Cache_Maven_Repo
displayName: 'Linux Maven Repo'
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
timeoutInMinutes: 30
pool:
vmImage: 'Ubuntu 16.04'
Expand Down Expand Up @@ -48,7 +48,7 @@ stages:

- job: Cache_Windows_Maven_Repo #windows has different line endings so the cache key is different
displayName: 'Windows Maven Repo'
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
timeoutInMinutes: 30
pool:
vmImage: 'vs2017-win2016'
Expand All @@ -71,7 +71,7 @@ stages:
inputs:
goals: 'package'
mavenOptions: $(MAVEN_OPTS)
options: '-B --settings azure-mvn-settings.xml -DskipTests=true -Dno-format -DskipDocs'
options: '-B --settings azure-mvn-settings.xml -DskipTests=true -Dno-format -DskipDocs'

#This stage builds the Quarkus artifacts needed for native image testing
- stage: initial_jdk8_stage${{parameters.expectUseVMs}}
Expand All @@ -80,7 +80,7 @@ stages:
jobs:
- job: Build_JDK8_Linux
displayName: 'Build JDK8 Linux'
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
timeoutInMinutes: 60
pool:
vmImage: 'Ubuntu 16.04'
Expand All @@ -99,7 +99,7 @@ stages:
jobs:
- job: Windows_Build
displayName: 'Windows JVM Build'
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
timeoutInMinutes: 60
pool:
# Always use hosted pool for windows
Expand All @@ -123,20 +123,20 @@ stages:

- job: Build_JDK11_Linux
timeoutInMinutes: 60
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
displayName: 'Linux JDK11 Build'
pool: ${{parameters.poolSettings}}
workspace:
clean: all

steps:
- template: jvm-build-steps.yaml
parameters:
jdk: '1.11'

- job: Build_JDK12_Linux
timeoutInMinutes: 60
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
displayName: 'Linux JDK12 Build'
pool: ${{parameters.poolSettings}}

Expand All @@ -149,7 +149,7 @@ stages:
jdk: '1.12'

- job: Run_TCKs
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
condition: and(eq(variables.LINUX_USE_VMS, ${{parameters.expectUseVMs}}),succeeded())
timeoutInMinutes: 60
pool: ${{parameters.poolSettings}}
workspace:
Expand Down Expand Up @@ -309,6 +309,7 @@ stages:
- 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,7 +31,7 @@ public void testGraphQlQuery() {

@Test
public void testWebSocketSubProtocol() throws Exception {
HttpClient httpClient = vertx.createHttpClient();
HttpClient httpClient = Vertx.vertx().createHttpClient();
WebSocketConnectOptions options = new WebSocketConnectOptions().setPort(getPortFromConfig())
.addSubProtocol("graphql-ws").setURI("/graphql");
CompletableFuture<Boolean> wsFuture = new CompletableFuture<>();
Expand Down

0 comments on commit 3fd3ce8

Please sign in to comment.