Skip to content

Commit 3a0006b

Browse files
committed
Exposes timeout in GraphQlSseHandler
Closes gh-1079
1 parent c784612 commit 3a0006b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlSseHandler.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.graphql.server.webmvc;
1818

1919
import java.io.IOException;
20+
import java.time.Duration;
2021
import java.util.Map;
2122
import java.util.function.Consumer;
2223

@@ -31,6 +32,7 @@
3132
import org.springframework.graphql.execution.SubscriptionPublisherException;
3233
import org.springframework.graphql.server.WebGraphQlHandler;
3334
import org.springframework.graphql.server.WebGraphQlResponse;
35+
import org.springframework.lang.Nullable;
3436
import org.springframework.web.context.request.async.AsyncRequestTimeoutException;
3537
import org.springframework.web.servlet.function.ServerRequest;
3638
import org.springframework.web.servlet.function.ServerResponse;
@@ -47,8 +49,29 @@
4749
*/
4850
public class GraphQlSseHandler extends AbstractGraphQlHttpHandler {
4951

52+
@Nullable
53+
private final Duration timeout;
54+
55+
56+
/**
57+
* Constructor with the handler to delegate to, and no timeout,
58+
* i.e. relying on underlying Server async request timeout.
59+
* @param graphQlHandler the handler to delegate to
60+
*/
5061
public GraphQlSseHandler(WebGraphQlHandler graphQlHandler) {
62+
this(graphQlHandler, null);
63+
}
64+
65+
/**
66+
* Variant constructor with a timeout to use for SSE subscriptions.
67+
* @param graphQlHandler the handler to delegate to
68+
* @param timeout the timeout value to set on
69+
* {@link org.springframework.web.context.request.async.AsyncWebRequest#setTimeout(Long)}
70+
* @since 1.3.3
71+
*/
72+
public GraphQlSseHandler(WebGraphQlHandler graphQlHandler, @Nullable Duration timeout) {
5173
super(graphQlHandler, null);
74+
this.timeout = timeout;
5275
}
5376

5477

@@ -76,7 +99,9 @@ protected ServerResponse prepareResponse(
7699
.toSpecification());
77100
});
78101

79-
return ServerResponse.sse(SseSubscriber.connect(resultFlux));
102+
return ((this.timeout != null) ?
103+
ServerResponse.sse(SseSubscriber.connect(resultFlux), this.timeout) :
104+
ServerResponse.sse(SseSubscriber.connect(resultFlux)));
80105
}
81106

82107

0 commit comments

Comments
 (0)