Skip to content

Commit 8a449c5

Browse files
committed
Merge branch '4.0.x'
Closes gh-50394
2 parents b9ee76e + 77faab2 commit 8a449c5

5 files changed

Lines changed: 38 additions & 9 deletions

File tree

module/spring-boot-graphql/src/main/java/org/springframework/boot/graphql/autoconfigure/reactive/GraphQlWebFluxAutoConfiguration.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,17 @@ static class WebSocketConfiguration {
180180
@Bean
181181
@ConditionalOnMissingBean
182182
GraphQlWebSocketHandler graphQlWebSocketHandler(WebGraphQlHandler webGraphQlHandler,
183-
GraphQlProperties properties, ServerCodecConfigurer configurer) {
184-
return new GraphQlWebSocketHandler(webGraphQlHandler, configurer,
185-
properties.getWebsocket().getConnectionInitTimeout(), properties.getWebsocket().getKeepAlive());
183+
GraphQlProperties properties, GraphQlCorsProperties corsProperties, ServerCodecConfigurer configurer) {
184+
CorsConfiguration corsConfiguration = corsProperties.toCorsConfiguration();
185+
if (corsConfiguration != null) {
186+
return new GraphQlWebSocketHandler(webGraphQlHandler, configurer,
187+
properties.getWebsocket().getConnectionInitTimeout(), properties.getWebsocket().getKeepAlive(),
188+
corsConfiguration);
189+
}
190+
else {
191+
return new GraphQlWebSocketHandler(webGraphQlHandler, configurer,
192+
properties.getWebsocket().getConnectionInitTimeout(), properties.getWebsocket().getKeepAlive());
193+
}
186194
}
187195

188196
@Bean

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,18 @@ static class WebSocketConfiguration {
186186
@Bean
187187
@ConditionalOnMissingBean
188188
GraphQlWebSocketHandler graphQlWebSocketHandler(WebGraphQlHandler webGraphQlHandler,
189-
GraphQlProperties properties, ObjectProvider<ServerHttpMessageConvertersCustomizer> customizers) {
190-
return new GraphQlWebSocketHandler(webGraphQlHandler, getJsonConverter(customizers),
191-
properties.getWebsocket().getConnectionInitTimeout(), properties.getWebsocket().getKeepAlive());
189+
GraphQlProperties properties, GraphQlCorsProperties corsProperties,
190+
ObjectProvider<ServerHttpMessageConvertersCustomizer> customizers) {
191+
CorsConfiguration corsConfiguration = corsProperties.toCorsConfiguration();
192+
if (corsConfiguration != null) {
193+
return new GraphQlWebSocketHandler(webGraphQlHandler, getJsonConverter(customizers),
194+
properties.getWebsocket().getConnectionInitTimeout(), properties.getWebsocket().getKeepAlive(),
195+
corsConfiguration);
196+
}
197+
else {
198+
return new GraphQlWebSocketHandler(webGraphQlHandler, getJsonConverter(customizers),
199+
properties.getWebsocket().getConnectionInitTimeout(), properties.getWebsocket().getKeepAlive());
200+
}
192201
}
193202

194203
private HttpMessageConverter<Object> getJsonConverter(

module/spring-boot-graphql/src/test/java/org/springframework/boot/graphql/autoconfigure/reactive/GraphQlWebFluxAutoConfigurationTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.function.Consumer;
2323

2424
import graphql.schema.idl.TypeRuntimeWiring;
25+
import org.assertj.core.api.InstanceOfAssertFactories;
2526
import org.jspecify.annotations.Nullable;
2627
import org.junit.jupiter.api.Test;
2728
import reactor.core.publisher.Mono;
@@ -263,13 +264,18 @@ void shouldConfigureWebSocketBeans() {
263264
void shouldConfigureWebSocketProperties() {
264265
this.contextRunner
265266
.withPropertyValues("spring.graphql.websocket.path=/ws",
266-
"spring.graphql.websocket.connection-init-timeout=120s", "spring.graphql.websocket.keep-alive=30s")
267+
"spring.graphql.websocket.connection-init-timeout=120s", "spring.graphql.websocket.keep-alive=30s",
268+
"spring.graphql.cors.allowed-origins=https://example.com")
267269
.run((context) -> {
268270
assertThat(context).hasSingleBean(GraphQlWebSocketHandler.class);
269271
GraphQlWebSocketHandler graphQlWebSocketHandler = context.getBean(GraphQlWebSocketHandler.class);
270272
assertThat(graphQlWebSocketHandler).extracting("initTimeoutDuration")
271273
.isEqualTo(Duration.ofSeconds(120));
272274
assertThat(graphQlWebSocketHandler).extracting("keepAliveDuration").isEqualTo(Duration.ofSeconds(30));
275+
assertThat(graphQlWebSocketHandler).extracting("corsConfiguration")
276+
.extracting("allowedOrigins")
277+
.asInstanceOf(InstanceOfAssertFactories.LIST)
278+
.containsExactly("https://example.com");
273279
});
274280
}
275281

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Optional;
2222

2323
import graphql.schema.idl.TypeRuntimeWiring;
24+
import org.assertj.core.api.InstanceOfAssertFactories;
2425
import org.assertj.core.api.ThrowingConsumer;
2526
import org.junit.jupiter.api.Test;
2627

@@ -243,13 +244,18 @@ void shouldConfigureWebSocketBeans() {
243244
void shouldConfigureWebSocketProperties() {
244245
this.contextRunner
245246
.withPropertyValues("spring.graphql.websocket.path=/ws",
246-
"spring.graphql.websocket.connection-init-timeout=120s", "spring.graphql.websocket.keep-alive=30s")
247+
"spring.graphql.websocket.connection-init-timeout=120s", "spring.graphql.websocket.keep-alive=30s",
248+
"spring.graphql.cors.allowed-origins=https://example.com")
247249
.run((context) -> {
248250
assertThat(context).hasSingleBean(GraphQlWebSocketHandler.class);
249251
GraphQlWebSocketHandler graphQlWebSocketHandler = context.getBean(GraphQlWebSocketHandler.class);
250252
assertThat(graphQlWebSocketHandler).extracting("initTimeoutDuration")
251253
.isEqualTo(Duration.ofSeconds(120));
252254
assertThat(graphQlWebSocketHandler).extracting("keepAliveDuration").isEqualTo(Duration.ofSeconds(30));
255+
assertThat(graphQlWebSocketHandler).extracting("corsConfiguration")
256+
.extracting("allowedOrigins")
257+
.asInstanceOf(InstanceOfAssertFactories.LIST)
258+
.containsExactly("https://example.com");
253259
});
254260
}
255261

platform/spring-boot-dependencies/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,7 @@ bom {
25722572
releaseNotes("https://github.com/spring-projects/spring-framework/releases/tag/v{version}")
25732573
}
25742574
}
2575-
library("Spring GraphQL", "2.0.3") {
2575+
library("Spring GraphQL", "2.0.4-SNAPSHOT") {
25762576
considerSnapshots()
25772577
group("org.springframework.graphql") {
25782578
modules = [

0 commit comments

Comments
 (0)