From 3177de59af470b3b2b1df068bc6d51d5f4461819 Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Mon, 27 Feb 2023 15:40:29 +0100 Subject: [PATCH] GraphQLWSHandler only works with connectionInitHandler set (#2373) See #2369 Signed-off-by: Thomas Segismont --- .../web/handler/graphql/impl/ws/ConnectionHandler.java | 1 + .../ext/web/handler/graphql/GraphQLWSTestsServer.java | 9 +++++---- vertx-web-graphql/tests/graphql-ws/graphql-ws.test.js | 7 +++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/vertx-web-graphql/src/main/java/io/vertx/ext/web/handler/graphql/impl/ws/ConnectionHandler.java b/vertx-web-graphql/src/main/java/io/vertx/ext/web/handler/graphql/impl/ws/ConnectionHandler.java index 5fed821ca2..85404f5c8e 100644 --- a/vertx-web-graphql/src/main/java/io/vertx/ext/web/handler/graphql/impl/ws/ConnectionHandler.java +++ b/vertx-web-graphql/src/main/java/io/vertx/ext/web/handler/graphql/impl/ws/ConnectionHandler.java @@ -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); } } diff --git a/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/GraphQLWSTestsServer.java b/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/GraphQLWSTestsServer.java index 16aa30cc97..ee2e87dc64 100644 --- a/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/GraphQLWSTestsServer.java +++ b/vertx-web-graphql/src/test/java/io/vertx/ext/web/handler/graphql/GraphQLWSTestsServer.java @@ -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. @@ -58,7 +57,9 @@ public void start(Promise 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")) { diff --git a/vertx-web-graphql/tests/graphql-ws/graphql-ws.test.js b/vertx-web-graphql/tests/graphql-ws/graphql-ws.test.js index e4e7e70cee..4398a61bf2 100644 --- a/vertx-web-graphql/tests/graphql-ws/graphql-ws.test.js +++ b/vertx-web-graphql/tests/graphql-ws/graphql-ws.test.js @@ -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( @@ -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); });