diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlAutoConfiguration.java index 9f04378ba..bb250cb1d 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlAutoConfiguration.java @@ -31,7 +31,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; @@ -65,18 +64,18 @@ public static class GraphQlSourceConfiguration { @Bean @ConditionalOnMissingBean - public RuntimeWiring runtimeWiring(ObjectProvider customizers) { + public RuntimeWiring runtimeWiring(ObjectProvider customizers) { RuntimeWiring.Builder builder = RuntimeWiring.newRuntimeWiring(); customizers.orderedStream().forEach((customizer) -> customizer.customize(builder)); return builder.build(); } @Bean - public GraphQlSource.Builder graphQlSourceBuilder(ApplicationContext applicationContext, GraphQlProperties properties, + public GraphQlSource.Builder graphQlSourceBuilder(ResourcePatternResolver resourcePatternResolver, GraphQlProperties properties, RuntimeWiring runtimeWiring, ObjectProvider exceptionResolversProvider, ObjectProvider instrumentationsProvider) throws IOException { - List schemaResources = resolveSchemaResources(applicationContext, properties.getSchema().getLocations()); + List schemaResources = resolveSchemaResources(resourcePatternResolver, properties.getSchema().getLocations()); return GraphQlSource.builder().schemaResources(schemaResources.toArray(new Resource[0])) .runtimeWiring(runtimeWiring) .exceptionResolvers(exceptionResolversProvider.orderedStream().collect(Collectors.toList())) diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlProperties.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlProperties.java index b57be4cee..9032b899c 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlProperties.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlProperties.java @@ -42,7 +42,7 @@ public class GraphQlProperties { private final GraphiQL graphiql = new GraphiQL(); - private final WebSocket websocket = new WebSocket(); + private final Websocket websocket = new Websocket(); public String getPath() { return this.path; @@ -60,7 +60,7 @@ public GraphiQL getGraphiql() { return this.graphiql; } - public WebSocket getWebsocket() { + public Websocket getWebsocket() { return this.websocket; } @@ -152,7 +152,7 @@ public void setEnabled(boolean enabled) { } } - public static class WebSocket { + public static class Websocket { /** * Path of the GraphQL WebSocket subscription endpoint. diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlServiceAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlServiceAutoConfiguration.java index 79581d49f..16e34ef82 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlServiceAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlServiceAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphQlAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlWebFluxAutoConfiguration.java similarity index 93% rename from graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphQlAutoConfiguration.java rename to graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlWebFluxAutoConfiguration.java index 2315ab691..341d0ab92 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphQlAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlWebFluxAutoConfiguration.java @@ -65,14 +65,15 @@ @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) @ConditionalOnClass(GraphQL.class) @ConditionalOnBean(GraphQlSource.class) -@AutoConfigureAfter(GraphQlAutoConfiguration.class) -public class WebFluxGraphQlAutoConfiguration { +@AutoConfigureAfter(GraphQlServiceAutoConfiguration.class) +public class GraphQlWebFluxAutoConfiguration { - private static final Log logger = LogFactory.getLog(WebFluxGraphQlAutoConfiguration.class); + private static final Log logger = LogFactory.getLog(GraphQlWebFluxAutoConfiguration.class); @Bean + @ConditionalOnBean(GraphQlService.class) @ConditionalOnMissingBean - public WebGraphQlHandler webGraphQlHandler(ObjectProvider interceptors, GraphQlService service) { + public WebGraphQlHandler webGraphQlHandler(GraphQlService service, ObjectProvider interceptors) { return WebGraphQlHandler.builder(service) .interceptors(interceptors.orderedStream().collect(Collectors.toList())).build(); } @@ -86,7 +87,6 @@ public GraphQlHttpHandler graphQlHttpHandler(WebGraphQlHandler webGraphQlHandler @Bean public RouterFunction graphQlEndpoint(GraphQlHttpHandler handler, GraphQlSource graphQlSource, GraphQlProperties properties, ResourceLoader resourceLoader) { - String graphQLPath = properties.getPath(); if (logger.isInfoEnabled()) { logger.info("GraphQL endpoint HTTP POST " + graphQLPath); @@ -96,7 +96,7 @@ public RouterFunction graphQlEndpoint(GraphQlHttpHandler handler .POST(graphQLPath, accept(MediaType.APPLICATION_JSON).and(contentType(MediaType.APPLICATION_JSON)), handler::handleRequest); if (properties.getGraphiql().isEnabled()) { Resource resource = resourceLoader.getResource("classpath:graphiql/index.html"); - WebFluxGraphiQlHandler graphiQlHandler = new WebFluxGraphiQlHandler(graphQLPath, resource); + GraphiQlWebFluxHandler graphiQlHandler = new GraphiQlWebFluxHandler(graphQLPath, resource); builder = builder.GET(properties.getGraphiql().getPath(), graphiQlHandler::showGraphiQlPage); } if (properties.getSchema().getPrinter().isEnabled()) { @@ -118,7 +118,6 @@ public static class WebSocketConfiguration { @ConditionalOnMissingBean public GraphQlWebSocketHandler graphQlWebSocketHandler(WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties, ServerCodecConfigurer configurer) { - return new GraphQlWebSocketHandler(webGraphQlHandler, configurer, properties.getWebsocket().getConnectionInitTimeout()); } @@ -126,7 +125,6 @@ public GraphQlWebSocketHandler graphQlWebSocketHandler(WebGraphQlHandler webGrap @Bean public HandlerMapping graphQlWebSocketEndpoint(GraphQlWebSocketHandler graphQlWebSocketHandler, GraphQlProperties properties) { - String path = properties.getWebsocket().getPath(); if (logger.isInfoEnabled()) { logger.info("GraphQL endpoint WebSocket " + path); diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphQlAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlWebMvcAutoConfiguration.java similarity index 92% rename from graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphQlAutoConfiguration.java rename to graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlWebMvcAutoConfiguration.java index 195a2b0c5..d38792d19 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphQlAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQlWebMvcAutoConfiguration.java @@ -72,16 +72,16 @@ @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @ConditionalOnClass(GraphQL.class) @ConditionalOnBean(GraphQlSource.class) -@AutoConfigureAfter(GraphQlAutoConfiguration.class) -public class WebMvcGraphQlAutoConfiguration { +@AutoConfigureAfter(GraphQlServiceAutoConfiguration.class) +public class GraphQlWebMvcAutoConfiguration { - private static final Log logger = LogFactory.getLog(WebMvcGraphQlAutoConfiguration.class); + private static final Log logger = LogFactory.getLog(GraphQlWebMvcAutoConfiguration.class); @Bean + @ConditionalOnBean(GraphQlService.class) @ConditionalOnMissingBean - public WebGraphQlHandler webGraphQlHandler(ObjectProvider interceptorsProvider, - GraphQlService service, ObjectProvider accessorsProvider) { - + public WebGraphQlHandler webGraphQlHandler(GraphQlService service, ObjectProvider interceptorsProvider, + ObjectProvider accessorsProvider) { return WebGraphQlHandler.builder(service) .interceptors(interceptorsProvider.orderedStream().collect(Collectors.toList())) .threadLocalAccessors(accessorsProvider.orderedStream().collect(Collectors.toList())).build(); @@ -96,7 +96,6 @@ public GraphQlHttpHandler graphQlHttpHandler(WebGraphQlHandler webGraphQlHandler @Bean public RouterFunction graphQlRouterFunction(GraphQlHttpHandler handler, GraphQlSource graphQlSource, GraphQlProperties properties, ResourceLoader resourceLoader) { - String graphQLPath = properties.getPath(); if (logger.isInfoEnabled()) { logger.info("GraphQL endpoint HTTP POST " + graphQLPath); @@ -106,7 +105,7 @@ public RouterFunction graphQlRouterFunction(GraphQlHttpHandler h .POST(graphQLPath, contentType(MediaType.APPLICATION_JSON).and(accept(MediaType.APPLICATION_JSON)), handler::handleRequest); if (properties.getGraphiql().isEnabled()) { Resource resource = resourceLoader.getResource("classpath:graphiql/index.html"); - WebMvcGraphiQlHandler graphiQLHandler = new WebMvcGraphiQlHandler(graphQLPath, resource); + GraphiQlWebMvcHandler graphiQLHandler = new GraphiQlWebMvcHandler(graphQLPath, resource); builder = builder.GET(properties.getGraphiql().getPath(), graphiQLHandler::showGraphiQlPage); } if (properties.getSchema().getPrinter().isEnabled()) { @@ -121,7 +120,7 @@ public RouterFunction graphQlRouterFunction(GraphQlHttpHandler h } @Configuration(proxyBeanMethods = false) - @ConditionalOnClass({ServerContainer.class, WebSocketHandler.class}) + @ConditionalOnClass({ ServerContainer.class, WebSocketHandler.class }) @ConditionalOnProperty(prefix = "spring.graphql.websocket", name = "path") public static class WebSocketConfiguration { @@ -129,7 +128,6 @@ public static class WebSocketConfiguration { @ConditionalOnMissingBean public GraphQlWebSocketHandler graphQlWebSocketHandler(WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties, HttpMessageConverters converters) { - // @formatter:off HttpMessageConverter converter = converters.getConverters().stream() .filter((candidate) -> candidate.canRead(Map.class, MediaType.APPLICATION_JSON)) diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphiQlHandler.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphiQlWebFluxHandler.java similarity index 88% rename from graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphiQlHandler.java rename to graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphiQlWebFluxHandler.java index 23ad47695..347efc163 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphiQlHandler.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphiQlWebFluxHandler.java @@ -25,20 +25,21 @@ /** * WebFlux functional handler for the GraphiQl UI. + * * @author Brian Clozel */ -class WebFluxGraphiQlHandler { +class GraphiQlWebFluxHandler { private final String graphQlPath; private final Resource graphiQlResource; - public WebFluxGraphiQlHandler(String graphQlPath, Resource graphiQlResource) { + GraphiQlWebFluxHandler(String graphQlPath, Resource graphiQlResource) { this.graphQlPath = graphQlPath; this.graphiQlResource = graphiQlResource; } - public Mono showGraphiQlPage(ServerRequest request) { + Mono showGraphiQlPage(ServerRequest request) { if (request.queryParam("path").isPresent()) { return ServerResponse.ok().contentType(MediaType.TEXT_HTML).bodyValue(this.graphiQlResource); } diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphiQlHandler.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphiQlWebMvcHandler.java similarity index 88% rename from graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphiQlHandler.java rename to graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphiQlWebMvcHandler.java index 25c26f2e6..7104cf53d 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphiQlHandler.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphiQlWebMvcHandler.java @@ -23,20 +23,21 @@ /** * Servlet.fn handler for the GraphiQl UI. + * * @author Brian Clozel */ -class WebMvcGraphiQlHandler { +class GraphiQlWebMvcHandler { private final String graphQlPath; private final Resource graphiQlResource; - public WebMvcGraphiQlHandler(String graphQlPath, Resource graphiQlResource) { + GraphiQlWebMvcHandler(String graphQlPath, Resource graphiQlResource) { this.graphQlPath = graphQlPath; this.graphiQlResource = graphiQlResource; } - public ServerResponse showGraphiQlPage(ServerRequest request) { + ServerResponse showGraphiQlPage(ServerRequest request) { if (request.param("path").isPresent()) { return ServerResponse.ok().contentType(MediaType.TEXT_HTML).body(this.graphiQlResource); } @@ -44,4 +45,5 @@ public ServerResponse showGraphiQlPage(ServerRequest request) { return ServerResponse.temporaryRedirect(request.uriBuilder().queryParam("path", this.graphQlPath).build()).build(); } } + } diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/RuntimeWiringCustomizer.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/RuntimeWiringBuilderCustomizer.java similarity index 66% rename from graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/RuntimeWiringCustomizer.java rename to graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/RuntimeWiringBuilderCustomizer.java index f18e53fcb..48e081fef 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/RuntimeWiringCustomizer.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/RuntimeWiringBuilderCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2020 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,19 @@ import graphql.schema.idl.RuntimeWiring; /** - * Callback interface that can be used to customize the GraphQL - * {@link RuntimeWiring.Builder}. + * Callback interface that can be implemented by beans wishing to customize the + * {@link RuntimeWiring} via a {@link RuntimeWiring.Builder} whilst retaining default + * auto-configuration. * * @author Brian Clozel * @since 1.0.0 */ @FunctionalInterface -public interface RuntimeWiringCustomizer { +public interface RuntimeWiringBuilderCustomizer { /** - * Callback to customize a {@link RuntimeWiring.Builder} instance. - * @param builder builder instance to customize + * Customize the {@link RuntimeWiring.Builder} instance. + * @param builder builder the builder to customize */ void customize(RuntimeWiring.Builder builder); diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/DefaultGraphQlTagsProvider.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/DefaultGraphQlTagsProvider.java index d8946e267..ec5fef556 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/DefaultGraphQlTagsProvider.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/DefaultGraphQlTagsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsAutoConfiguration.java index 449026698..866769ec9 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsInstrumentation.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsInstrumentation.java index 06747ff01..9c6ae2f60 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsInstrumentation.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsInstrumentation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsProperties.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsProperties.java index 0f1c923bf..32d35fa52 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsProperties.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlMetricsProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlTagsContributor.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlTagsContributor.java index eb22a52e7..7520d178b 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlTagsContributor.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlTagsContributor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlTagsProvider.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlTagsProvider.java index 77f33011d..0696fc800 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlTagsProvider.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/actuate/metrics/GraphQlTagsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/graphql-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 000000000..1e44e8576 --- /dev/null +++ b/graphql-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,8 @@ +{ + "properties": [ + { + "name": "spring.graphql.locations", + "defaultValue": "classpath:graphql/" + } + ] +} \ No newline at end of file diff --git a/graphql-spring-boot-starter/src/main/resources/META-INF/spring.factories b/graphql-spring-boot-starter/src/main/resources/META-INF/spring.factories index 423ff5fad..dd0ca6022 100644 --- a/graphql-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/graphql-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -2,12 +2,14 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.graphql.boot.actuate.metrics.GraphQlMetricsAutoConfiguration,\ org.springframework.graphql.boot.GraphQlAutoConfiguration,\ org.springframework.graphql.boot.GraphQlServiceAutoConfiguration,\ -org.springframework.graphql.boot.WebFluxGraphQlAutoConfiguration,\ -org.springframework.graphql.boot.WebMvcGraphQlAutoConfiguration +org.springframework.graphql.boot.GraphQlWebFluxAutoConfiguration,\ +org.springframework.graphql.boot.GraphQlWebMvcAutoConfiguration + # Spring Test @AutoConfigureGraphQlTester org.springframework.graphql.boot.test.tester.AutoConfigureGraphQlTester=\ org.springframework.graphql.boot.test.tester.WebTestClientMockMvcAutoConfiguration,\ org.springframework.graphql.boot.test.tester.GraphQlTesterAutoConfiguration + # Spring Test ContextCustomizerFactories org.springframework.test.context.ContextCustomizerFactory=\ org.springframework.graphql.boot.test.tester.GraphQlTesterContextCustomizerFactory \ No newline at end of file diff --git a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlAutoConfigurationTests.java b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlAutoConfigurationTests.java index 55fca42b9..0678485e2 100644 --- a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlAutoConfigurationTests.java +++ b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/WebFluxApplicationContextTests.java b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlWebFluxAutoConfigurationTests.java similarity index 75% rename from graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/WebFluxApplicationContextTests.java rename to graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlWebFluxAutoConfigurationTests.java index 81a5f11db..4a2e24405 100644 --- a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/WebFluxApplicationContextTests.java +++ b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlWebFluxAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2020-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,9 +27,7 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration; import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration; -import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.graphql.web.WebInterceptor; @@ -40,15 +38,20 @@ // @formatter:off -class WebFluxApplicationContextTests { - - private static final AutoConfigurations AUTO_CONFIGURATIONS = AutoConfigurations.of( - HttpHandlerAutoConfiguration.class, WebFluxAutoConfiguration.class, CodecsAutoConfiguration.class, - JacksonAutoConfiguration.class, GraphQlAutoConfiguration.class, GraphQlServiceAutoConfiguration.class, - WebFluxGraphQlAutoConfiguration.class); +class GraphQlWebFluxAutoConfigurationTests { private static final String BASE_URL = "https://spring.example.org/graphql"; + private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(HttpHandlerAutoConfiguration.class, WebFluxAutoConfiguration.class, + CodecsAutoConfiguration.class, JacksonAutoConfiguration.class, GraphQlAutoConfiguration.class, + GraphQlServiceAutoConfiguration.class, GraphQlWebFluxAutoConfiguration.class)) + .withUserConfiguration(DataFetchersConfiguration.class, CustomWebInterceptor.class) + .withPropertyValues( + "spring.main.web-application-type=reactive", + "spring.graphql.schema.printer.enabled=true", + "spring.graphql.schema.locations=classpath:books/"); + @Test void query() { testWithWebClient((client) -> { @@ -56,7 +59,7 @@ void query() { " bookById(id: \\\"book-1\\\"){ " + " id" + " name" + - " pageCount" + + " pageCount" + " author" + " }" + "}"; @@ -124,7 +127,7 @@ void schemaEndpoint() { } private void testWithWebClient(Consumer consumer) { - testWithApplicationContext((context) -> { + this.contextRunner.run((context) -> { WebTestClient client = WebTestClient.bindToApplicationContext(context) .configureClient() .defaultHeaders((headers) -> { @@ -137,22 +140,11 @@ private void testWithWebClient(Consumer consumer) { }); } - private void testWithApplicationContext(ContextConsumer consumer) { - new ReactiveWebApplicationContextRunner() - .withConfiguration(AUTO_CONFIGURATIONS) - .withUserConfiguration(DataFetchersConfiguration.class, CustomWebInterceptor.class) - .withPropertyValues( - "spring.main.web-application-type=reactive", - "spring.graphql.schema.printer.enabled=true", - "spring.graphql.schema.locations=classpath:books/") - .run(consumer); - } - @Configuration(proxyBeanMethods = false) - public static class DataFetchersConfiguration { + static class DataFetchersConfiguration { @Bean - public RuntimeWiringCustomizer bookDataFetcher() { + RuntimeWiringBuilderCustomizer bookDataFetcher() { return (runtimeWiring) -> runtimeWiring.type(TypeRuntimeWiring.newTypeWiring("Query") .dataFetcher("bookById", GraphQlDataFetchers.getBookByIdDataFetcher())); @@ -161,10 +153,10 @@ public RuntimeWiringCustomizer bookDataFetcher() { } @Configuration(proxyBeanMethods = false) - public static class CustomWebInterceptor { + static class CustomWebInterceptor { @Bean - public WebInterceptor customWebInterceptor() { + WebInterceptor customWebInterceptor() { return (input, next) -> next.handle(input).map((output) -> output.transform((builder) -> builder.responseHeader("X-Custom-Header", "42"))); } diff --git a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/WebMvcApplicationContextTests.java b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlWebMvcAutoConfigurationTests.java similarity index 78% rename from graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/WebMvcApplicationContextTests.java rename to graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlWebMvcAutoConfigurationTests.java index a87eb4f9b..ff7c726fd 100644 --- a/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/WebMvcApplicationContextTests.java +++ b/graphql-spring-boot-starter/src/test/java/org/springframework/graphql/boot/GraphQlWebMvcAutoConfigurationTests.java @@ -44,13 +44,18 @@ // @formatter:off -class WebMvcApplicationContextTests { - - public static final AutoConfigurations AUTO_CONFIGURATIONS = AutoConfigurations.of( - DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class, - HttpMessageConvertersAutoConfiguration.class, JacksonAutoConfiguration.class, - GraphQlAutoConfiguration.class, GraphQlServiceAutoConfiguration.class, - WebMvcGraphQlAutoConfiguration.class); +class GraphQlWebMvcAutoConfigurationTests { + + private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(DispatcherServletAutoConfiguration.class, + WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, + JacksonAutoConfiguration.class, GraphQlAutoConfiguration.class, + GraphQlServiceAutoConfiguration.class, GraphQlWebMvcAutoConfiguration.class)) + .withUserConfiguration(DataFetchersConfiguration.class, CustomWebInterceptor.class) + .withPropertyValues( + "spring.main.web-application-type=servlet", + "spring.graphql.schema.printer.enabled=true", + "spring.graphql.schema.locations=classpath:books/"); @Test void endpointHandlesGraphQlQuery() { @@ -108,20 +113,13 @@ void schemaEndpoint() { } private void testWith(MockMvcConsumer mockMvcConsumer) { - new WebApplicationContextRunner() - .withConfiguration(AUTO_CONFIGURATIONS) - .withUserConfiguration(DataFetchersConfiguration.class, CustomWebInterceptor.class) - .withPropertyValues( - "spring.main.web-application-type=servlet", - "spring.graphql.schema.printer.enabled=true", - "spring.graphql.schema.locations=classpath:books/") - .run((context) -> { - MediaType mediaType = MediaType.APPLICATION_JSON; - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context) - .defaultRequest(post("/graphql").contentType(mediaType).accept(mediaType)) - .build(); - mockMvcConsumer.accept(mockMvc); - }); + this.contextRunner.run((context) -> { + MediaType mediaType = MediaType.APPLICATION_JSON; + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context) + .defaultRequest(post("/graphql").contentType(mediaType).accept(mediaType)) + .build(); + mockMvcConsumer.accept(mockMvc); + }); } private interface MockMvcConsumer { @@ -131,10 +129,10 @@ private interface MockMvcConsumer { } @Configuration(proxyBeanMethods = false) - public static class DataFetchersConfiguration { + static class DataFetchersConfiguration { @Bean - public RuntimeWiringCustomizer bookDataFetcher() { + RuntimeWiringBuilderCustomizer bookDataFetcher() { return (builder) -> builder.type(TypeRuntimeWiring.newTypeWiring("Query") .dataFetcher("bookById", GraphQlDataFetchers.getBookByIdDataFetcher())); } @@ -142,10 +140,10 @@ public RuntimeWiringCustomizer bookDataFetcher() { } @Configuration(proxyBeanMethods = false) - public static class CustomWebInterceptor { + static class CustomWebInterceptor { @Bean - public WebInterceptor customWebInterceptor() { + WebInterceptor customWebInterceptor() { return (input, next) -> next.handle(input).map((output) -> output.transform((builder) -> builder.responseHeader("X-Custom-Header", "42"))); } diff --git a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleWiring.java b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleWiring.java index d8da884fe..597917902 100644 --- a/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleWiring.java +++ b/samples/webflux-security/src/main/java/io/spring/sample/graphql/SampleWiring.java @@ -20,11 +20,11 @@ import graphql.schema.idl.RuntimeWiring; -import org.springframework.graphql.boot.RuntimeWiringCustomizer; +import org.springframework.graphql.boot.RuntimeWiringBuilderCustomizer; import org.springframework.stereotype.Component; @Component -public class SampleWiring implements RuntimeWiringCustomizer { +public class SampleWiring implements RuntimeWiringBuilderCustomizer { final EmployeeService employeeService; diff --git a/samples/webflux-websocket/src/main/java/io/spring/sample/graphql/SampleWiring.java b/samples/webflux-websocket/src/main/java/io/spring/sample/graphql/SampleWiring.java index a4c88d521..f06066c78 100644 --- a/samples/webflux-websocket/src/main/java/io/spring/sample/graphql/SampleWiring.java +++ b/samples/webflux-websocket/src/main/java/io/spring/sample/graphql/SampleWiring.java @@ -18,11 +18,11 @@ import graphql.schema.idl.RuntimeWiring; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.graphql.boot.RuntimeWiringCustomizer; +import org.springframework.graphql.boot.RuntimeWiringBuilderCustomizer; import org.springframework.stereotype.Component; @Component -public class SampleWiring implements RuntimeWiringCustomizer { +public class SampleWiring implements RuntimeWiringBuilderCustomizer { private final DataRepository repository; diff --git a/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SampleWiring.java b/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SampleWiring.java index e08d27099..c63324951 100644 --- a/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SampleWiring.java +++ b/samples/webmvc-http-security/src/main/java/io/spring/sample/graphql/SampleWiring.java @@ -5,11 +5,11 @@ import graphql.schema.idl.RuntimeWiring; -import org.springframework.graphql.boot.RuntimeWiringCustomizer; +import org.springframework.graphql.boot.RuntimeWiringBuilderCustomizer; import org.springframework.stereotype.Component; @Component -public class SampleWiring implements RuntimeWiringCustomizer { +public class SampleWiring implements RuntimeWiringBuilderCustomizer { final EmployeeService employeeService; diff --git a/samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/GreetingDataWiring.java b/samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/GreetingDataWiring.java index 60f726840..e68909d5f 100644 --- a/samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/GreetingDataWiring.java +++ b/samples/webmvc-http/src/main/java/io/spring/sample/graphql/greeting/GreetingDataWiring.java @@ -2,7 +2,7 @@ import graphql.schema.idl.RuntimeWiring; -import org.springframework.graphql.boot.RuntimeWiringCustomizer; +import org.springframework.graphql.boot.RuntimeWiringBuilderCustomizer; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; @@ -10,7 +10,7 @@ import static org.springframework.web.context.request.RequestAttributes.SCOPE_REQUEST; @Component -public class GreetingDataWiring implements RuntimeWiringCustomizer { +public class GreetingDataWiring implements RuntimeWiringBuilderCustomizer { @Override public void customize(RuntimeWiring.Builder builder) { diff --git a/samples/webmvc-http/src/main/java/io/spring/sample/graphql/project/ProjectDataWiring.java b/samples/webmvc-http/src/main/java/io/spring/sample/graphql/project/ProjectDataWiring.java index 5f493e6e5..ec080418c 100644 --- a/samples/webmvc-http/src/main/java/io/spring/sample/graphql/project/ProjectDataWiring.java +++ b/samples/webmvc-http/src/main/java/io/spring/sample/graphql/project/ProjectDataWiring.java @@ -1,11 +1,11 @@ package io.spring.sample.graphql.project; import graphql.schema.idl.RuntimeWiring; -import org.springframework.graphql.boot.RuntimeWiringCustomizer; +import org.springframework.graphql.boot.RuntimeWiringBuilderCustomizer; import org.springframework.stereotype.Component; @Component -public class ProjectDataWiring implements RuntimeWiringCustomizer { +public class ProjectDataWiring implements RuntimeWiringBuilderCustomizer { private final SpringProjectsClient client; diff --git a/samples/webmvc-http/src/main/java/io/spring/sample/graphql/repository/ArtifactRepositoryDataWiring.java b/samples/webmvc-http/src/main/java/io/spring/sample/graphql/repository/ArtifactRepositoryDataWiring.java index 5c09959de..0bb8de645 100644 --- a/samples/webmvc-http/src/main/java/io/spring/sample/graphql/repository/ArtifactRepositoryDataWiring.java +++ b/samples/webmvc-http/src/main/java/io/spring/sample/graphql/repository/ArtifactRepositoryDataWiring.java @@ -2,12 +2,12 @@ import graphql.schema.idl.RuntimeWiring; -import org.springframework.graphql.boot.RuntimeWiringCustomizer; +import org.springframework.graphql.boot.RuntimeWiringBuilderCustomizer; import org.springframework.graphql.data.QuerydslDataFetcher; import org.springframework.stereotype.Component; @Component -public class ArtifactRepositoryDataWiring implements RuntimeWiringCustomizer { +public class ArtifactRepositoryDataWiring implements RuntimeWiringBuilderCustomizer { private final ArtifactRepositories repositories;