Skip to content

Commit ceba707

Browse files
committed
SubscriptionException for onConnect and enable keep alive by default
1 parent fa4dc1f commit ceba707

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/main/java/graphql/servlet/ApolloSubscriptionConnectionListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ public interface ApolloSubscriptionConnectionListener extends SubscriptionConnec
77
String CONNECT_RESULT_KEY = "CONNECT_RESULT";
88

99
default boolean isKeepAliveEnabled() {
10-
return false;
10+
return true;
1111
}
1212

13-
default Optional<Object> onConnect(Object payload) {
13+
default Optional<Object> onConnect(Object payload) throws SubscriptionException {
1414
return Optional.empty();
1515
}
1616

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package graphql.servlet;
2+
3+
public class SubscriptionException extends Exception {
4+
5+
private Object payload;
6+
7+
public SubscriptionException() {
8+
}
9+
10+
public SubscriptionException(Object payload) {
11+
this.payload = payload;
12+
}
13+
14+
public Object getPayload() {
15+
return payload;
16+
}
17+
18+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import graphql.ExecutionResult;
77
import graphql.servlet.ApolloSubscriptionConnectionListener;
88
import graphql.servlet.GraphQLSingleInvocationInput;
9+
import graphql.servlet.SubscriptionException;
910
import org.slf4j.Logger;
1011
import org.slf4j.LoggerFactory;
1112

@@ -63,8 +64,8 @@ public void onMessage(HandshakeRequest request, Session session, WsSessionSubscr
6364
try {
6465
Optional<Object> connectionResponse = connectionListener.onConnect(message.getPayload());
6566
connectionResponse.ifPresent(it -> session.getUserProperties().put(ApolloSubscriptionConnectionListener.CONNECT_RESULT_KEY, it));
66-
} catch (Throwable t) {
67-
sendMessage(session, OperationMessage.Type.GQL_CONNECTION_ERROR, message.getId(), t);
67+
} catch (SubscriptionException e) {
68+
sendMessage(session, OperationMessage.Type.GQL_CONNECTION_ERROR, message.getId(), e.getPayload());
6869
return;
6970
}
7071

0 commit comments

Comments
 (0)