Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,18 +64,18 @@ public static class GraphQlSourceConfiguration {

@Bean
@ConditionalOnMissingBean
public RuntimeWiring runtimeWiring(ObjectProvider<RuntimeWiringCustomizer> customizers) {
public RuntimeWiring runtimeWiring(ObjectProvider<RuntimeWiringBuilderCustomizer> 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<DataFetcherExceptionResolver> exceptionResolversProvider,
ObjectProvider<Instrumentation> instrumentationsProvider) throws IOException {

List<Resource> schemaResources = resolveSchemaResources(applicationContext, properties.getSchema().getLocations());
List<Resource> schemaResources = resolveSchemaResources(resourcePatternResolver, properties.getSchema().getLocations());
return GraphQlSource.builder().schemaResources(schemaResources.toArray(new Resource[0]))
.runtimeWiring(runtimeWiring)
.exceptionResolvers(exceptionResolversProvider.orderedStream().collect(Collectors.toList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,7 +60,7 @@ public GraphiQL getGraphiql() {
return this.graphiql;
}

public WebSocket getWebsocket() {
public Websocket getWebsocket() {
return this.websocket;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ public void setEnabled(boolean enabled) {
}
}

public static class WebSocket {
public static class Websocket {

/**
* Path of the GraphQL WebSocket subscription endpoint.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebInterceptor> interceptors, GraphQlService service) {
public WebGraphQlHandler webGraphQlHandler(GraphQlService service, ObjectProvider<WebInterceptor> interceptors) {
return WebGraphQlHandler.builder(service)
.interceptors(interceptors.orderedStream().collect(Collectors.toList())).build();
}
Expand All @@ -86,7 +87,6 @@ public GraphQlHttpHandler graphQlHttpHandler(WebGraphQlHandler webGraphQlHandler
@Bean
public RouterFunction<ServerResponse> graphQlEndpoint(GraphQlHttpHandler handler, GraphQlSource graphQlSource,
GraphQlProperties properties, ResourceLoader resourceLoader) {

String graphQLPath = properties.getPath();
if (logger.isInfoEnabled()) {
logger.info("GraphQL endpoint HTTP POST " + graphQLPath);
Expand All @@ -96,7 +96,7 @@ public RouterFunction<ServerResponse> 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()) {
Expand All @@ -118,15 +118,13 @@ public static class WebSocketConfiguration {
@ConditionalOnMissingBean
public GraphQlWebSocketHandler graphQlWebSocketHandler(WebGraphQlHandler webGraphQlHandler,
GraphQlProperties properties, ServerCodecConfigurer configurer) {

return new GraphQlWebSocketHandler(webGraphQlHandler, configurer,
properties.getWebsocket().getConnectionInitTimeout());
}

@Bean
public HandlerMapping graphQlWebSocketEndpoint(GraphQlWebSocketHandler graphQlWebSocketHandler,
GraphQlProperties properties) {

String path = properties.getWebsocket().getPath();
if (logger.isInfoEnabled()) {
logger.info("GraphQL endpoint WebSocket " + path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebInterceptor> interceptorsProvider,
GraphQlService service, ObjectProvider<ThreadLocalAccessor> accessorsProvider) {

public WebGraphQlHandler webGraphQlHandler(GraphQlService service, ObjectProvider<WebInterceptor> interceptorsProvider,
ObjectProvider<ThreadLocalAccessor> accessorsProvider) {
return WebGraphQlHandler.builder(service)
.interceptors(interceptorsProvider.orderedStream().collect(Collectors.toList()))
.threadLocalAccessors(accessorsProvider.orderedStream().collect(Collectors.toList())).build();
Expand All @@ -96,7 +96,6 @@ public GraphQlHttpHandler graphQlHttpHandler(WebGraphQlHandler webGraphQlHandler
@Bean
public RouterFunction<ServerResponse> graphQlRouterFunction(GraphQlHttpHandler handler, GraphQlSource graphQlSource,
GraphQlProperties properties, ResourceLoader resourceLoader) {

String graphQLPath = properties.getPath();
if (logger.isInfoEnabled()) {
logger.info("GraphQL endpoint HTTP POST " + graphQLPath);
Expand All @@ -106,7 +105,7 @@ public RouterFunction<ServerResponse> 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()) {
Expand All @@ -121,15 +120,14 @@ public RouterFunction<ServerResponse> 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 {

@Bean
@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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerResponse> showGraphiQlPage(ServerRequest request) {
Mono<ServerResponse> showGraphiQlPage(ServerRequest request) {
if (request.queryParam("path").isPresent()) {
return ServerResponse.ok().contentType(MediaType.TEXT_HTML).bodyValue(this.graphiQlResource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,27 @@

/**
* 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);
}
else {
return ServerResponse.temporaryRedirect(request.uriBuilder().queryParam("path", this.graphQlPath).build()).build();
}
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"properties": [
{
"name": "spring.graphql.locations",
"defaultValue": "classpath:graphql/"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading