Skip to content

Commit

Permalink
GraphQLWSHandler only works with connectionInitHandler set (vert-x3#2373
Browse files Browse the repository at this point in the history
)

See vert-x3#2369

Signed-off-by: Thomas Segismont <[email protected]>
  • Loading branch information
tsegismont authored Feb 27, 2023
1 parent a8d76f1 commit 3177de5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ void connectionInit(MessageImpl msg) {
state = new InitializingState(connectionPromise.future());
connectionInitHandler.handle(new ConnectionInitEventImpl(msg, connectionPromise));
} else {
sendMessage(null, CONNECTION_ACK, null);
state = new ReadyState(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@

import java.util.stream.Stream;

import static graphql.schema.idl.RuntimeWiring.newRuntimeWiring;
import static io.vertx.core.http.HttpMethod.GET;
import static io.vertx.core.http.HttpMethod.POST;
import static graphql.schema.idl.RuntimeWiring.*;
import static io.vertx.core.http.HttpMethod.*;

/**
* Backend for the GraphQLWS compatibility tests.
Expand All @@ -58,7 +57,9 @@ public void start(Promise<Void> startPromise) throws Exception {

GraphQL graphQL = setupGraphQL();

router.route("/graphql").handler(GraphQLWSHandler.create(graphQL)
router.route("/graphql").handler(GraphQLWSHandler.create(graphQL));

router.route("/graphqlWithInitHandler").handler(GraphQLWSHandler.create(graphQL)
.connectionInitHandler(connectionInitEvent -> {
JsonObject payload = connectionInitEvent.message().message().getJsonObject("payload");
if (payload != null && payload.containsKey("rejectMessage")) {
Expand Down
7 changes: 5 additions & 2 deletions vertx-web-graphql/tests/graphql-ws/graphql-ws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ test('subscription', async () => {

test('ws link subscription with failed promise', async () => {
client = createClient({
url: 'ws://localhost:8080/graphql',
url: 'ws://localhost:8080/graphqlWithInitHandler',
webSocketImpl: WebSocket,
connectionParams: {
rejectMessage: "test"
}
});

let err;
try {
await new Promise((resolve, reject) => {
client.subscribe(
Expand All @@ -98,6 +99,8 @@ test('ws link subscription with failed promise', async () => {
);
});
} catch (e) {
expect(e.code).toEqual(4401);
err = e;
}
expect(err).toBeDefined();
expect(err.code).toEqual(4401);
});

0 comments on commit 3177de5

Please sign in to comment.