Skip to content

Commit c2ab2dd

Browse files
committed
Merge pull request #42966 from nosan
* pr/42966: Support timeout property for GraphQL over SSE Closes gh-42966
2 parents 23607ee + 85b1c56 commit c2ab2dd

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/GraphQlProperties.java

+23
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class GraphQlProperties {
4343

4444
private final Rsocket rsocket = new Rsocket();
4545

46+
private final Sse sse = new Sse();
47+
4648
public Graphiql getGraphiql() {
4749
return this.graphiql;
4850
}
@@ -67,6 +69,10 @@ public Rsocket getRsocket() {
6769
return this.rsocket;
6870
}
6971

72+
public Sse getSse() {
73+
return this.sse;
74+
}
75+
7076
public static class Schema {
7177

7278
/**
@@ -265,4 +271,21 @@ public void setMapping(String mapping) {
265271

266272
}
267273

274+
public static class Sse {
275+
276+
/**
277+
* Time required for concurrent handling to complete.
278+
*/
279+
private Duration timeout;
280+
281+
public Duration getTimeout() {
282+
return this.timeout;
283+
}
284+
285+
public void setTimeout(Duration timeout) {
286+
this.timeout = timeout;
287+
}
288+
289+
}
290+
268291
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration;
3838
import org.springframework.boot.autoconfigure.graphql.GraphQlCorsProperties;
3939
import org.springframework.boot.autoconfigure.graphql.GraphQlProperties;
40+
import org.springframework.boot.autoconfigure.graphql.GraphQlProperties.Sse;
4041
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
4142
import org.springframework.boot.context.properties.EnableConfigurationProperties;
4243
import org.springframework.context.annotation.Bean;
@@ -97,8 +98,9 @@ public GraphQlHttpHandler graphQlHttpHandler(WebGraphQlHandler webGraphQlHandler
9798

9899
@Bean
99100
@ConditionalOnMissingBean
100-
public GraphQlSseHandler graphQlSseHandler(WebGraphQlHandler webGraphQlHandler) {
101-
return new GraphQlSseHandler(webGraphQlHandler);
101+
public GraphQlSseHandler graphQlSseHandler(WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties) {
102+
Sse sse = properties.getSse();
103+
return new GraphQlSseHandler(webGraphQlHandler, sse.getTimeout());
102104
}
103105

104106
@Bean

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.springframework.graphql.server.WebGraphQlHandler;
4242
import org.springframework.graphql.server.WebGraphQlInterceptor;
4343
import org.springframework.graphql.server.webmvc.GraphQlHttpHandler;
44+
import org.springframework.graphql.server.webmvc.GraphQlSseHandler;
4445
import org.springframework.graphql.server.webmvc.GraphQlWebSocketHandler;
4546
import org.springframework.http.HttpHeaders;
4647
import org.springframework.http.HttpStatus;
@@ -78,6 +79,15 @@ void shouldContributeDefaultBeans() {
7879
.doesNotHaveBean(GraphQlWebSocketHandler.class));
7980
}
8081

82+
@Test
83+
void shouldConfigureSseTimeout() {
84+
this.contextRunner.withPropertyValues("spring.graphql.sse.timeout=10s").run((context) -> {
85+
assertThat(context).hasSingleBean(GraphQlSseHandler.class);
86+
GraphQlSseHandler handler = context.getBean(GraphQlSseHandler.class);
87+
assertThat(handler).hasFieldOrPropertyWithValue("timeout", Duration.ofSeconds(10));
88+
});
89+
}
90+
8191
@Test
8292
void simpleQueryShouldWork() {
8393
withMockMvc((mvc) -> {

0 commit comments

Comments
 (0)