Skip to content

Commit ef63c2e

Browse files
committed
Preserve websocket session in FallbackSubscriptionProtocolHandler fix #137
1 parent 36ce5ff commit ef63c2e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/main/java/graphql/servlet/internal/FallbackSubscriptionProtocolHandler.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package graphql.servlet.internal;
22

3+
import graphql.servlet.GraphQLSingleInvocationInput;
4+
35
import javax.websocket.Session;
46
import javax.websocket.server.HandshakeRequest;
57
import java.io.IOException;
@@ -20,18 +22,23 @@ public FallbackSubscriptionProtocolHandler(SubscriptionHandlerInput subscription
2022

2123
@Override
2224
public void onMessage(HandshakeRequest request, Session session, WsSessionSubscriptions subscriptions, String text) throws Exception {
25+
GraphQLSingleInvocationInput graphQLSingleInvocationInput = createInvocationInput(session, text);
2326
subscribe(
2427
session,
25-
input.getQueryInvoker().query(
26-
input.getInvocationInputFactory().create(
27-
input.getGraphQLObjectMapper().readGraphQLRequest(text)
28-
)
29-
),
28+
input.getQueryInvoker().query(graphQLSingleInvocationInput),
3029
subscriptions,
3130
UUID.randomUUID().toString()
3231
);
3332
}
3433

34+
private GraphQLSingleInvocationInput createInvocationInput(Session session, String text) throws IOException {
35+
GraphQLRequest graphQLRequest = input.getGraphQLObjectMapper().readGraphQLRequest(text);
36+
HandshakeRequest handshakeRequest = (HandshakeRequest) session.getUserProperties()
37+
.get(HandshakeRequest.class.getName());
38+
39+
return input.getInvocationInputFactory().create(graphQLRequest, session, handshakeRequest);
40+
}
41+
3542
@Override
3643
protected void sendDataMessage(Session session, String id, Object payload) {
3744
sender.send(session, payload);

0 commit comments

Comments
 (0)