Skip to content

Commit

Permalink
Support timeout property for GraphQL over SSE
Browse files Browse the repository at this point in the history
  • Loading branch information
nosan committed Nov 1, 2024
1 parent 8f6aabc commit 4aec694
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -67,6 +69,10 @@ public Rsocket getRsocket() {
return this.rsocket;
}

public Sse getSse() {
return this.sse;
}

public static class Schema {

/**
Expand Down Expand Up @@ -265,4 +271,21 @@ public void setMapping(String mapping) {

}

public static class Sse {

/**
* Set the time required for concurrent handling to complete.
*/
private Duration timeout;

public Duration getTimeout() {
return this.timeout;
}

public void setTimeout(Duration timeout) {
this.timeout = timeout;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;
Expand Down Expand Up @@ -97,8 +98,9 @@ public GraphQlHttpHandler graphQlHttpHandler(WebGraphQlHandler webGraphQlHandler

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
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;
Expand Down Expand Up @@ -78,6 +79,15 @@ void shouldContributeDefaultBeans() {
.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) -> {
Expand Down

0 comments on commit 4aec694

Please sign in to comment.