Skip to content

Commit

Permalink
SR-GQL 1.4.3 + reflect recent websocket changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmartisk committed Feb 15, 2022
1 parent 13500f2 commit 4f1c03b
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
<module name="org.slf4j"/>

<module name="io.undertow.websocket"/>
<module name="javax.websocket.api"/>
</dependencies>
</module>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<!-- Libraries provided by this feature pack. These variables directly affect what will be in
the built feature pack. -->
<version.io.smallrye.graphql>1.4.2</version.io.smallrye.graphql>
<version.io.smallrye.graphql>1.4.3</version.io.smallrye.graphql>
<version.org.eclipse.microprofile.graphql>1.1.0</version.org.eclipse.microprofile.graphql>
<version.com.graphql-java>17.3</version.com.graphql-java>
<version.com.graphql-java.dataloader>2.2.3</version.com.graphql-java.dataloader>
Expand Down
10 changes: 10 additions & 0 deletions quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
<artifactId>smallrye-graphql-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
<scope>provided</scope>
</dependency>
<!-- TODO: smallrye-graphql-api has a "provided" dep on this so it's not brought in transitively,
so maybe it should be "compile" in SR? -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wildfly.extras.quickstart.microprofile.graphql;

import io.smallrye.graphql.api.Subscription;
import io.smallrye.mutiny.Multi;
import org.eclipse.microprofile.graphql.DefaultValue;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
Expand Down Expand Up @@ -55,4 +57,9 @@ public List<String> desc(@Source List<Film> films) {
return films.stream().map(film -> "Awesome").collect(Collectors.toList());
}

@Subscription
public Multi<String> hello() {
return Multi.createFrom().items("1", "2", "3");
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.wildfly.extension.microprofile.graphql;

import io.smallrye.graphql.entry.http.GraphQLServerWebSocket;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

/**
* WebSocket endpoint that exposes GraphQL over websockets.
* Just wrap the original GraphQLServerWebSocket class from SmallRye. The reason we're not using it directly is that
* I don't know how to make the deployer see the annotations on that class - if we try to use it directly then
* the undertow deployer will fail. So we extend that class, re-declare its annotations and delegate everything to it.
*/
@ServerEndpoint(value = "/graphql", subprotocols = { "graphql-transport-ws", "graphql-ws" })
public class WildFlyGraphQLServerWebSocket extends GraphQLServerWebSocket {

@OnOpen
public void onOpen(Session session) {
super.onOpen(session);
}

@OnClose
public void onClose(Session session) {
super.onClose(session);
}

@OnError
public void onError(Session session, Throwable throwable) {
super.onError(session, throwable);
}

@OnMessage
public void handleMessage(Session session, String message) {
super.handleMessage(session, message);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.metadata.web.spec.ListenerMetaData;
import org.jboss.metadata.web.spec.ServletMappingMetaData;
import org.wildfly.extension.microprofile.graphql.SubscriptionWebSocket;
import org.wildfly.extension.microprofile.graphql.WildFlyGraphQLServerWebSocket;
import org.wildfly.extension.microprofile.graphql._private.MicroProfileGraphQLLogger;
import org.wildfly.extension.undertow.deployment.UndertowAttachments;

Expand Down Expand Up @@ -70,7 +70,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
// if the GraphQL API contains subscriptions, deploy the relevant web socket endpoint that handles them
if (!compositeIndex.getAnnotations(ANNOTATION_SUBSCRIPTION).isEmpty()) {
WebSocketDeploymentInfo webSocketDeploymentInfo = deploymentUnit.getAttachment(UndertowAttachments.WEB_SOCKET_DEPLOYMENT_INFO);
webSocketDeploymentInfo.addEndpoint(SubscriptionWebSocket.class);
webSocketDeploymentInfo.addEndpoint(WildFlyGraphQLServerWebSocket.class);
mergedJBossWebMetaData.setEnableWebSockets(true);
}

Expand Down
9 changes: 9 additions & 0 deletions testsuite/client-vertx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package org.wildfly.extras.graphql.test.client.vertx.typesafe;

import org.eclipse.microprofile.graphql.GraphQLApi;
import io.smallrye.graphql.api.Subscription;
import io.smallrye.graphql.client.typesafe.api.GraphQLClientApi;
import io.smallrye.mutiny.Multi;
import org.eclipse.microprofile.graphql.Query;

@GraphQLApi
public interface FunnyApi {
import java.io.Closeable;

@GraphQLClientApi
public interface FunnyApi extends Closeable {

@Query("random")
Funny getRandomFunny();

@Subscription("count")
Multi<Integer> count(int fromInclusive, int toExclusive);

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package org.wildfly.extras.graphql.test.client.vertx.typesafe;

import io.smallrye.graphql.api.Subscription;
import io.smallrye.mutiny.Multi;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Query;

import java.util.concurrent.ThreadLocalRandom;

public class FunnyApiImpl implements FunnyApi {
@GraphQLApi
public class FunnyApiImpl {

@Override
@Query("random")
public Funny getRandomFunny() {
Funny funny = new Funny();
funny.setNumber(ThreadLocalRandom.current().nextInt(1, 1000));
return funny;
}

@Subscription("count")
public Multi<Integer> count(int fromInclusive, int toExclusive) {
return Multi.createFrom().range(fromInclusive, toExclusive);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.wildfly.extras.graphql.test.client.vertx.typesafe;

import io.smallrye.graphql.client.typesafe.api.TypesafeGraphQLClientBuilder;
import io.smallrye.graphql.client.websocket.WebsocketSubprotocol;
import io.smallrye.mutiny.helpers.test.AssertSubscriber;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
Expand All @@ -11,6 +13,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.time.Duration;

/**
* Testing the typesafe client running outside the WildFly VM. Using JAX-RS transport.
*/
Expand All @@ -21,8 +26,8 @@ public class TypesafeClientOutsideVMTestCase {
@Deployment(testable = false)
public static WebArchive deployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class, "funny.war")
.addClasses(Funny.class, FunnyApi.class, FunnyApiImpl.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
.addClasses(Funny.class, FunnyApi.class, FunnyApiImpl.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
return war;
}

Expand All @@ -34,4 +39,32 @@ public void testCall() {
Assert.assertTrue(funny.getNumber() < 1000);
}

@Test
public void testSubscription_graphqlWSProtocol() throws IOException {
try (FunnyApi funnyApi = TypesafeGraphQLClientBuilder.newBuilder()
.endpoint("http://localhost:8080/funny/graphql")
.subprotocols(WebsocketSubprotocol.GRAPHQL_WS)
.build(FunnyApi.class)) {
AssertSubscriber<Integer> subscriber = new AssertSubscriber<>(5);
funnyApi.count(0, 5).subscribe(subscriber);
subscriber.await(Duration.ofSeconds(10));
subscriber.assertCompleted();
subscriber.assertItems(0, 1, 2, 3, 4);
}
}

@Test
public void testSubscription_graphqlTransportWSProtocol() throws IOException {
try (FunnyApi funnyApi = TypesafeGraphQLClientBuilder.newBuilder()
.endpoint("http://localhost:8080/funny/graphql")
.subprotocols(WebsocketSubprotocol.GRAPHQL_TRANSPORT_WS)
.build(FunnyApi.class)) {
AssertSubscriber<Integer> subscriber = new AssertSubscriber<>(5);
funnyApi.count(0, 5).subscribe(subscriber);
subscriber.await(Duration.ofSeconds(10));
subscriber.assertCompleted();
subscriber.assertItems(0, 1, 2, 3, 4);
}
}

}
Loading

0 comments on commit 4f1c03b

Please sign in to comment.