Merge pull request #42966 from nosan

* pr/42966:
  Support timeout property for GraphQL over SSE

Closes gh-42966
This commit is contained in:
Phillip Webb 2024-11-01 14:13:44 -07:00
commit c2ab2ddd6c
3 changed files with 37 additions and 2 deletions

View File

@ -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 {
return this.rsocket;
}
public Sse getSse() {
return this.sse;
}
public static class Schema {
/**
@ -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;
}
}
}

View File

@ -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 {
@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

View File

@ -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 {
.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) -> {