Browse Source

Support timeout property for GraphQL over SSE

See gh-42966
pull/42974/head
Dmytro Nosan 1 year ago committed by Phillip Webb
parent
commit
85b1c567f1
  1. 23
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/GraphQlProperties.java
  2. 6
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfiguration.java
  3. 10
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java

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

@ -43,6 +43,8 @@ public class GraphQlProperties { @@ -43,6 +43,8 @@ public class GraphQlProperties {
private final Rsocket rsocket = new Rsocket();
private final Sse sse = new Sse();
public Graphiql getGraphiql() {
return this.graphiql;
}
@ -67,6 +69,10 @@ public class GraphQlProperties { @@ -67,6 +69,10 @@ public class GraphQlProperties {
return this.rsocket;
}
public Sse getSse() {
return this.sse;
}
public static class Schema {
/**
@ -265,4 +271,21 @@ public class GraphQlProperties { @@ -265,4 +271,21 @@ public class GraphQlProperties {
}
public static class Sse {
/**
* Time required for concurrent handling to complete.
*/
private Duration timeout;
public Duration getTimeout() {
return this.timeout;
}
public void setTimeout(Duration timeout) {
this.timeout = timeout;
}
}
}

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

@ -37,6 +37,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat @@ -37,6 +37,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration;
import org.springframework.boot.autoconfigure.graphql.GraphQlCorsProperties;
import org.springframework.boot.autoconfigure.graphql.GraphQlProperties;
import org.springframework.boot.autoconfigure.graphql.GraphQlProperties.Sse;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@ -97,8 +98,9 @@ public class GraphQlWebMvcAutoConfiguration { @@ -97,8 +98,9 @@ public class GraphQlWebMvcAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public GraphQlSseHandler graphQlSseHandler(WebGraphQlHandler webGraphQlHandler) {
return new GraphQlSseHandler(webGraphQlHandler);
public GraphQlSseHandler graphQlSseHandler(WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties) {
Sse sse = properties.getSse();
return new GraphQlSseHandler(webGraphQlHandler, sse.getTimeout());
}
@Bean

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

@ -41,6 +41,7 @@ import org.springframework.graphql.execution.RuntimeWiringConfigurer; @@ -41,6 +41,7 @@ import org.springframework.graphql.execution.RuntimeWiringConfigurer;
import org.springframework.graphql.server.WebGraphQlHandler;
import org.springframework.graphql.server.WebGraphQlInterceptor;
import org.springframework.graphql.server.webmvc.GraphQlHttpHandler;
import org.springframework.graphql.server.webmvc.GraphQlSseHandler;
import org.springframework.graphql.server.webmvc.GraphQlWebSocketHandler;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@ -78,6 +79,15 @@ class GraphQlWebMvcAutoConfigurationTests { @@ -78,6 +79,15 @@ class GraphQlWebMvcAutoConfigurationTests {
.doesNotHaveBean(GraphQlWebSocketHandler.class));
}
@Test
void shouldConfigureSseTimeout() {
this.contextRunner.withPropertyValues("spring.graphql.sse.timeout=10s").run((context) -> {
assertThat(context).hasSingleBean(GraphQlSseHandler.class);
GraphQlSseHandler handler = context.getBean(GraphQlSseHandler.class);
assertThat(handler).hasFieldOrPropertyWithValue("timeout", Duration.ofSeconds(10));
});
}
@Test
void simpleQueryShouldWork() {
withMockMvc((mvc) -> {

Loading…
Cancel
Save