Support for annotated DataFetcher's
Closes gh-61, gh-90
This commit is contained in:
@@ -36,6 +36,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.graphql.data.method.AnnotatedDataFetcherRegistrar;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInterceptor;
|
||||
@@ -73,6 +74,18 @@ public class GraphQlWebFluxAutoConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GraphQlWebFluxAutoConfiguration.class);
|
||||
|
||||
@Bean
|
||||
public AnnotatedDataFetcherRegistrar dataFetcherRegistrar(ServerCodecConfigurer configurer) {
|
||||
AnnotatedDataFetcherRegistrar registrar = new AnnotatedDataFetcherRegistrar();
|
||||
registrar.setServerCodecConfigurer(configurer);
|
||||
return registrar;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RuntimeWiringBuilderCustomizer annotatedDataFetcherRuntimeWiringCustomizer(AnnotatedDataFetcherRegistrar registrar) {
|
||||
return registrar::register;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(GraphQlService.class)
|
||||
@ConditionalOnMissingBean
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.graphql.data.method.AnnotatedDataFetcherRegistrar;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.execution.ThreadLocalAccessor;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
@@ -51,7 +52,7 @@ import org.springframework.graphql.web.webmvc.SchemaHandler;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.GenericHttpMessageConverter;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.function.RouterFunction;
|
||||
import org.springframework.web.servlet.function.RouterFunctions;
|
||||
@@ -80,6 +81,28 @@ public class GraphQlWebMvcAutoConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GraphQlWebMvcAutoConfiguration.class);
|
||||
|
||||
|
||||
@Bean
|
||||
public AnnotatedDataFetcherRegistrar dataFetcherRegistrar(HttpMessageConverters converters) {
|
||||
AnnotatedDataFetcherRegistrar registrar = new AnnotatedDataFetcherRegistrar();
|
||||
registrar.setJsonMessageConverter(getJsonConverter(converters));
|
||||
return registrar;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static GenericHttpMessageConverter<Object> getJsonConverter(HttpMessageConverters converters) {
|
||||
return converters.getConverters().stream()
|
||||
.filter((candidate) -> candidate.canRead(Map.class, MediaType.APPLICATION_JSON))
|
||||
.findFirst()
|
||||
.map(converter -> (GenericHttpMessageConverter<Object>) converter)
|
||||
.orElseThrow(() -> new IllegalStateException("No JSON converter"));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RuntimeWiringBuilderCustomizer annotatedDataFetcherRuntimeWiringCustomizer(AnnotatedDataFetcherRegistrar registrar) {
|
||||
return registrar::register;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(GraphQlService.class)
|
||||
@ConditionalOnMissingBean
|
||||
@@ -138,12 +161,7 @@ public class GraphQlWebMvcAutoConfiguration {
|
||||
public GraphQlWebSocketHandler graphQlWebSocketHandler(WebGraphQlHandler webGraphQlHandler,
|
||||
GraphQlProperties properties, HttpMessageConverters converters) {
|
||||
|
||||
HttpMessageConverter<?> converter = converters.getConverters().stream()
|
||||
.filter((candidate) -> candidate.canRead(Map.class, MediaType.APPLICATION_JSON))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("No JSON converter"));
|
||||
|
||||
return new GraphQlWebSocketHandler(webGraphQlHandler, converter,
|
||||
return new GraphQlWebSocketHandler(webGraphQlHandler, getJsonConverter(converters),
|
||||
properties.getWebsocket().getConnectionInitTimeout());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user