Replace QL with Ql for consistency with Spring naming
This commit is contained in:
@@ -29,22 +29,22 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.graphql.execution.DataFetcherExceptionResolver;
|
||||
import org.springframework.graphql.execution.GraphQLSource;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(GraphQL.class)
|
||||
@ConditionalOnMissingBean(GraphQLSource.class)
|
||||
@EnableConfigurationProperties(GraphQLProperties.class)
|
||||
public class GraphQLAutoConfiguration {
|
||||
@ConditionalOnMissingBean(GraphQlSource.class)
|
||||
@EnableConfigurationProperties(GraphQlProperties.class)
|
||||
public class GraphQlAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public GraphQLSource graphQLSource(GraphQLSource.Builder builder) {
|
||||
public GraphQlSource graphQlSource(GraphQlSource.Builder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(GraphQLSource.Builder.class)
|
||||
static class GraphQLSourceConfiguration {
|
||||
@ConditionalOnMissingBean(GraphQlSource.Builder.class)
|
||||
static class GraphQlSourceConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@@ -55,13 +55,13 @@ public class GraphQLAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GraphQLSource.Builder graphQLSourceBuilder(
|
||||
GraphQLProperties properties, RuntimeWiring runtimeWiring,
|
||||
public GraphQlSource.Builder graphQlSourceBuilder(
|
||||
GraphQlProperties properties, RuntimeWiring runtimeWiring,
|
||||
ObjectProvider<DataFetcherExceptionResolver> exceptionResolversProvider,
|
||||
ResourceLoader resourceLoader, ObjectProvider<Instrumentation> instrumentationsProvider) {
|
||||
|
||||
String schemaLocation = properties.getSchema().getLocation();
|
||||
return GraphQLSource.builder()
|
||||
return GraphQlSource.builder()
|
||||
.schemaResource(resourceLoader.getResource(schemaLocation))
|
||||
.runtimeWiring(runtimeWiring)
|
||||
.exceptionResolvers(exceptionResolversProvider.orderedStream().collect(Collectors.toList()))
|
||||
@@ -20,7 +20,7 @@ import java.time.Duration;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "spring.graphql")
|
||||
public class GraphQLProperties {
|
||||
public class GraphQlProperties {
|
||||
|
||||
/**
|
||||
* Path at which to expose a GraphQL request HTTP endpoint.
|
||||
@@ -22,20 +22,20 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.graphql.GraphQLService;
|
||||
import org.springframework.graphql.execution.ExecutionGraphQLService;
|
||||
import org.springframework.graphql.execution.GraphQLSource;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.graphql.execution.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(GraphQL.class)
|
||||
@ConditionalOnMissingBean(GraphQLService.class)
|
||||
@AutoConfigureAfter(GraphQLAutoConfiguration.class)
|
||||
public class GraphQLServiceAutoConfiguration {
|
||||
@ConditionalOnMissingBean(GraphQlService.class)
|
||||
@AutoConfigureAfter(GraphQlAutoConfiguration.class)
|
||||
public class GraphQlServiceAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GraphQLService graphQLService(GraphQLSource graphQLSource) {
|
||||
return new ExecutionGraphQLService(graphQLSource);
|
||||
public GraphQlService graphQlService(GraphQlSource graphQlSource) {
|
||||
return new ExecutionGraphQlService(graphQlSource);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,12 +35,12 @@ import org.springframework.context.annotation.Bean;
|
||||
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.execution.GraphQLSource;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInterceptor;
|
||||
import org.springframework.graphql.web.webflux.GraphQLHttpHandler;
|
||||
import org.springframework.graphql.web.webflux.GraphQLWebSocketHandler;
|
||||
import org.springframework.graphql.web.webflux.GraphQlHttpHandler;
|
||||
import org.springframework.graphql.web.webflux.GraphQlWebSocketHandler;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
import org.springframework.web.reactive.HandlerMapping;
|
||||
@@ -56,28 +56,28 @@ import static org.springframework.web.reactive.function.server.RequestPredicates
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
|
||||
@ConditionalOnClass(GraphQL.class)
|
||||
@ConditionalOnBean(GraphQLSource.class)
|
||||
@AutoConfigureAfter(GraphQLAutoConfiguration.class)
|
||||
public class WebFluxGraphQLAutoConfiguration {
|
||||
@ConditionalOnBean(GraphQlSource.class)
|
||||
@AutoConfigureAfter(GraphQlAutoConfiguration.class)
|
||||
public class WebFluxGraphQlAutoConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(WebFluxGraphQLAutoConfiguration.class);
|
||||
private static final Log logger = LogFactory.getLog(WebFluxGraphQlAutoConfiguration.class);
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WebGraphQLHandler webGraphQLHandler(ObjectProvider<WebInterceptor> interceptors, GraphQLService service) {
|
||||
public WebGraphQlHandler webGraphQlHandler(ObjectProvider<WebInterceptor> interceptors, GraphQlService service) {
|
||||
return WebInterceptor.createHandler(interceptors.orderedStream().collect(Collectors.toList()), service);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GraphQLHttpHandler graphQLHttpHandler(WebGraphQLHandler webGraphQLHandler) {
|
||||
return new GraphQLHttpHandler(webGraphQLHandler);
|
||||
public GraphQlHttpHandler graphQlHttpHandler(WebGraphQlHandler webGraphQlHandler) {
|
||||
return new GraphQlHttpHandler(webGraphQlHandler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RouterFunction<ServerResponse> graphQLEndpoint(GraphQLHttpHandler handler, GraphQLSource graphQLSource,
|
||||
GraphQLProperties properties, ResourceLoader resourceLoader) {
|
||||
public RouterFunction<ServerResponse> graphQlEndpoint(GraphQlHttpHandler handler, GraphQlSource graphQlSource,
|
||||
GraphQlProperties properties, ResourceLoader resourceLoader) {
|
||||
|
||||
String path = properties.getPath();
|
||||
Resource resource = resourceLoader.getResource("classpath:graphiql/index.html");
|
||||
@@ -90,7 +90,7 @@ public class WebFluxGraphQLAutoConfiguration {
|
||||
if (properties.getSchema().getPrinter().isEnabled()) {
|
||||
SchemaPrinter schemaPrinter = new SchemaPrinter();
|
||||
builder = builder.GET(path + properties.getSchema().getPrinter().getPath(),
|
||||
req -> ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).bodyValue(schemaPrinter.print(graphQLSource.schema())));
|
||||
req -> ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).bodyValue(schemaPrinter.print(graphQlSource.schema())));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
@@ -100,23 +100,23 @@ public class WebFluxGraphQLAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GraphQLWebSocketHandler graphQLWebSocketHandler(
|
||||
WebGraphQLHandler webGraphQLHandler, GraphQLProperties properties, ServerCodecConfigurer configurer) {
|
||||
public GraphQlWebSocketHandler graphQlWebSocketHandler(
|
||||
WebGraphQlHandler webGraphQlHandler, GraphQlProperties properties, ServerCodecConfigurer configurer) {
|
||||
|
||||
return new GraphQLWebSocketHandler(
|
||||
webGraphQLHandler, configurer, properties.getWebsocket().getConnectionInitTimeout());
|
||||
return new GraphQlWebSocketHandler(
|
||||
webGraphQlHandler, configurer, properties.getWebsocket().getConnectionInitTimeout());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandlerMapping graphQLWebSocketEndpoint(
|
||||
GraphQLWebSocketHandler graphQLWebSocketHandler, GraphQLProperties properties) {
|
||||
public HandlerMapping graphQlWebSocketEndpoint(
|
||||
GraphQlWebSocketHandler graphQlWebSocketHandler, GraphQlProperties properties) {
|
||||
|
||||
String path = properties.getWebsocket().getPath();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("GraphQL endpoint WebSocket " + path);
|
||||
}
|
||||
WebSocketHandlerMapping handlerMapping = new WebSocketHandlerMapping();
|
||||
handlerMapping.setUrlMap(Collections.singletonMap(path, graphQLWebSocketHandler));
|
||||
handlerMapping.setUrlMap(Collections.singletonMap(path, graphQlWebSocketHandler));
|
||||
handlerMapping.setOrder(-2); // Ahead of HTTP endpoint ("routerFunctionMapping" bean)
|
||||
return handlerMapping;
|
||||
}
|
||||
@@ -39,12 +39,12 @@ import org.springframework.context.annotation.Bean;
|
||||
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.execution.GraphQLSource;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInterceptor;
|
||||
import org.springframework.graphql.web.webmvc.GraphQLHttpHandler;
|
||||
import org.springframework.graphql.web.webmvc.GraphQLWebSocketHandler;
|
||||
import org.springframework.graphql.web.webmvc.GraphQlHttpHandler;
|
||||
import org.springframework.graphql.web.webmvc.GraphQlWebSocketHandler;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
@@ -63,28 +63,28 @@ import static org.springframework.web.servlet.function.RequestPredicates.content
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
||||
@ConditionalOnClass(GraphQL.class)
|
||||
@ConditionalOnBean(GraphQLSource.class)
|
||||
@AutoConfigureAfter(GraphQLAutoConfiguration.class)
|
||||
public class WebMvcGraphQLAutoConfiguration {
|
||||
@ConditionalOnBean(GraphQlSource.class)
|
||||
@AutoConfigureAfter(GraphQlAutoConfiguration.class)
|
||||
public class WebMvcGraphQlAutoConfiguration {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(WebMvcGraphQLAutoConfiguration.class);
|
||||
private static final Log logger = LogFactory.getLog(WebMvcGraphQlAutoConfiguration.class);
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WebGraphQLHandler webGraphQLHandler(ObjectProvider<WebInterceptor> interceptors, GraphQLService service) {
|
||||
public WebGraphQlHandler webGraphQlHandler(ObjectProvider<WebInterceptor> interceptors, GraphQlService service) {
|
||||
return WebInterceptor.createHandler(interceptors.orderedStream().collect(Collectors.toList()), service);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GraphQLHttpHandler graphQLHttpHandler(WebGraphQLHandler webGraphQLHandler) {
|
||||
return new GraphQLHttpHandler(webGraphQLHandler);
|
||||
public GraphQlHttpHandler graphQlHttpHandler(WebGraphQlHandler webGraphQlHandler) {
|
||||
return new GraphQlHttpHandler(webGraphQlHandler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RouterFunction<ServerResponse> graphQLRouterFunction(GraphQLHttpHandler handler, GraphQLSource graphQLSource,
|
||||
GraphQLProperties properties, ResourceLoader resourceLoader) {
|
||||
public RouterFunction<ServerResponse> graphQlRouterFunction(GraphQlHttpHandler handler, GraphQlSource graphQlSource,
|
||||
GraphQlProperties properties, ResourceLoader resourceLoader) {
|
||||
|
||||
String path = properties.getPath();
|
||||
Resource resource = resourceLoader.getResource("classpath:graphiql/index.html");
|
||||
@@ -97,7 +97,7 @@ public class WebMvcGraphQLAutoConfiguration {
|
||||
if (properties.getSchema().getPrinter().isEnabled()) {
|
||||
SchemaPrinter schemaPrinter = new SchemaPrinter();
|
||||
builder = builder.GET(path + properties.getSchema().getPrinter().getPath(),
|
||||
req -> ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).body(schemaPrinter.print(graphQLSource.schema())));
|
||||
req -> ServerResponse.ok().contentType(MediaType.TEXT_PLAIN).body(schemaPrinter.print(graphQlSource.schema())));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
@@ -109,20 +109,20 @@ public class WebMvcGraphQLAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GraphQLWebSocketHandler graphQLWebSocketHandler(
|
||||
WebGraphQLHandler webGraphQLHandler, GraphQLProperties properties, HttpMessageConverters converters) {
|
||||
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, properties.getWebsocket().getConnectionInitTimeout());
|
||||
return new GraphQlWebSocketHandler(
|
||||
webGraphQlHandler, converter, properties.getWebsocket().getConnectionInitTimeout());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandlerMapping graphQLWebSocketMapping(GraphQLWebSocketHandler handler, GraphQLProperties properties) {
|
||||
public HandlerMapping graphQlWebSocketMapping(GraphQlWebSocketHandler handler, GraphQlProperties properties) {
|
||||
String path = properties.getWebsocket().getPath();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("GraphQL endpoint WebSocket " + path);
|
||||
@@ -26,19 +26,19 @@ import graphql.schema.DataFetcher;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
|
||||
public class DefaultGraphQLTagsProvider implements GraphQLTagsProvider {
|
||||
public class DefaultGraphQlTagsProvider implements GraphQlTagsProvider {
|
||||
|
||||
private final List<GraphQLTagsContributor> contributors;
|
||||
private final List<GraphQlTagsContributor> contributors;
|
||||
|
||||
public DefaultGraphQLTagsProvider(List<GraphQLTagsContributor> contributors) {
|
||||
public DefaultGraphQlTagsProvider(List<GraphQlTagsContributor> contributors) {
|
||||
this.contributors = contributors;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Iterable<Tag> getExecutionTags(InstrumentationExecutionParameters parameters, ExecutionResult result, Throwable exception) {
|
||||
Tags tags = Tags.of(GraphQLTags.executionOutcome(result, exception));
|
||||
for (GraphQLTagsContributor contributor : this.contributors) {
|
||||
Tags tags = Tags.of(GraphQlTags.executionOutcome(result, exception));
|
||||
for (GraphQlTagsContributor contributor : this.contributors) {
|
||||
tags = tags.and(contributor.getExecutionTags(parameters, result, exception));
|
||||
}
|
||||
return tags;
|
||||
@@ -46,8 +46,8 @@ public class DefaultGraphQLTagsProvider implements GraphQLTagsProvider {
|
||||
|
||||
@Override
|
||||
public Iterable<Tag> getErrorTags(InstrumentationExecutionParameters parameters, GraphQLError error) {
|
||||
Tags tags = Tags.of(GraphQLTags.errorType(error), GraphQLTags.errorPath(error));
|
||||
for (GraphQLTagsContributor contributor : this.contributors) {
|
||||
Tags tags = Tags.of(GraphQlTags.errorType(error), GraphQlTags.errorPath(error));
|
||||
for (GraphQlTagsContributor contributor : this.contributors) {
|
||||
tags = tags.and(contributor.getErrorTags(parameters, error));
|
||||
}
|
||||
return tags;
|
||||
@@ -55,8 +55,8 @@ public class DefaultGraphQLTagsProvider implements GraphQLTagsProvider {
|
||||
|
||||
@Override
|
||||
public Iterable<Tag> getDataFetchingTags(DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters, Throwable exception) {
|
||||
Tags tags = Tags.of(GraphQLTags.dataFetchingOutcome(exception), GraphQLTags.dataFetchingPath(parameters));
|
||||
for (GraphQLTagsContributor contributor : this.contributors) {
|
||||
Tags tags = Tags.of(GraphQlTags.dataFetchingOutcome(exception), GraphQlTags.dataFetchingPath(parameters));
|
||||
for (GraphQlTagsContributor contributor : this.contributors) {
|
||||
tags = tags.and(contributor.getDataFetchingTags(dataFetcher, parameters, exception));
|
||||
}
|
||||
return tags;
|
||||
@@ -40,18 +40,18 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter({MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class,
|
||||
SimpleMetricsExportAutoConfiguration.class})
|
||||
@ConditionalOnBean(MeterRegistry.class)
|
||||
@EnableConfigurationProperties(GraphQLMetricsProperties.class)
|
||||
public class GraphQLMetricsAutoConfiguration {
|
||||
@EnableConfigurationProperties(GraphQlMetricsProperties.class)
|
||||
public class GraphQlMetricsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(GraphQLTagsProvider.class)
|
||||
public DefaultGraphQLTagsProvider graphQLTagsProvider(ObjectProvider<GraphQLTagsContributor> contributors) {
|
||||
return new DefaultGraphQLTagsProvider(contributors.orderedStream().collect(Collectors.toList()));
|
||||
@ConditionalOnMissingBean(GraphQlTagsProvider.class)
|
||||
public DefaultGraphQlTagsProvider graphQlTagsProvider(ObjectProvider<GraphQlTagsContributor> contributors) {
|
||||
return new DefaultGraphQlTagsProvider(contributors.orderedStream().collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public GraphQLMetricsInstrumentation graphQLMetricsInstrumentation(MeterRegistry meterRegistry,
|
||||
GraphQLTagsProvider tagsProvider, GraphQLMetricsProperties properties) {
|
||||
return new GraphQLMetricsInstrumentation(meterRegistry, tagsProvider, properties.getAutotime());
|
||||
public GraphQlMetricsInstrumentation graphQlMetricsInstrumentation(MeterRegistry meterRegistry,
|
||||
GraphQlTagsProvider tagsProvider, GraphQlMetricsProperties properties) {
|
||||
return new GraphQlMetricsInstrumentation(meterRegistry, tagsProvider, properties.getAutotime());
|
||||
}
|
||||
}
|
||||
@@ -32,15 +32,15 @@ import io.micrometer.core.instrument.Timer;
|
||||
|
||||
import org.springframework.boot.actuate.metrics.AutoTimer;
|
||||
|
||||
public class GraphQLMetricsInstrumentation extends SimpleInstrumentation {
|
||||
public class GraphQlMetricsInstrumentation extends SimpleInstrumentation {
|
||||
|
||||
private final MeterRegistry registry;
|
||||
|
||||
private final GraphQLTagsProvider tagsProvider;
|
||||
private final GraphQlTagsProvider tagsProvider;
|
||||
|
||||
private final AutoTimer autoTimer;
|
||||
|
||||
public GraphQLMetricsInstrumentation(MeterRegistry registry, GraphQLTagsProvider tagsProvider, AutoTimer autoTimer) {
|
||||
public GraphQlMetricsInstrumentation(MeterRegistry registry, GraphQlTagsProvider tagsProvider, AutoTimer autoTimer) {
|
||||
this.registry = registry;
|
||||
this.tagsProvider = tagsProvider;
|
||||
this.autoTimer = autoTimer;
|
||||
@@ -24,7 +24,7 @@ import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
* This class could be merged with {@link org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties}
|
||||
*/
|
||||
@ConfigurationProperties("management.metrics.graphql")
|
||||
public class GraphQLMetricsProperties {
|
||||
public class GraphQlMetricsProperties {
|
||||
|
||||
/**
|
||||
* Auto-timed queries settings.
|
||||
@@ -32,7 +32,7 @@ import io.micrometer.core.instrument.Tag;
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public final class GraphQLTags {
|
||||
public final class GraphQlTags {
|
||||
|
||||
private static final Tag OUTCOME_SUCCESS = Tag.of("outcome", "SUCCESS");
|
||||
|
||||
@@ -23,7 +23,7 @@ import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchPar
|
||||
import graphql.schema.DataFetcher;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
|
||||
public interface GraphQLTagsContributor {
|
||||
public interface GraphQlTagsContributor {
|
||||
|
||||
Iterable<Tag> getExecutionTags(InstrumentationExecutionParameters parameters, ExecutionResult result, Throwable exception);
|
||||
|
||||
@@ -23,7 +23,7 @@ import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchPar
|
||||
import graphql.schema.DataFetcher;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
|
||||
public interface GraphQLTagsProvider {
|
||||
public interface GraphQlTagsProvider {
|
||||
|
||||
Iterable<Tag> getExecutionTags(InstrumentationExecutionParameters parameters, ExecutionResult result, Throwable exception);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Auto-configuration classes to configure
|
||||
* {@link org.springframework.graphql.execution.GraphQLSource},
|
||||
* {@link org.springframework.graphql.GraphQLService}, and HTTP and WebSocket
|
||||
* {@link org.springframework.graphql.execution.GraphQlSource},
|
||||
* {@link org.springframework.graphql.GraphQlService}, and HTTP and WebSocket
|
||||
* endpoints.
|
||||
*/
|
||||
@NonNullApi
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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.actuate.metrics.GraphQlMetricsAutoConfiguration,\
|
||||
org.springframework.graphql.boot.GraphQlAutoConfiguration,\
|
||||
org.springframework.graphql.boot.GraphQlServiceAutoConfiguration,\
|
||||
org.springframework.graphql.boot.WebFluxGraphQlAutoConfiguration,\
|
||||
org.springframework.graphql.boot.WebMvcGraphQlAutoConfiguration
|
||||
|
||||
@@ -23,17 +23,17 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.graphql.execution.GraphQLSource;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link GraphQLAutoConfiguration}
|
||||
* Tests for {@link GraphQlAutoConfiguration}
|
||||
*/
|
||||
class GraphQLAutoConfigurationTests {
|
||||
class GraphQlAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(GraphQLAutoConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(GraphQlAutoConfiguration.class));
|
||||
|
||||
|
||||
@Test
|
||||
@@ -48,26 +48,26 @@ class GraphQLAutoConfigurationTests {
|
||||
void shouldCreateBuilderWithSdl() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.graphql.schema.location:classpath:books/schema.graphqls")
|
||||
.run((context) -> assertThat(context).hasSingleBean(GraphQLSource.class));
|
||||
.run((context) -> assertThat(context).hasSingleBean(GraphQlSource.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseProgrammaticallyDefinedBuilder() {
|
||||
contextRunner
|
||||
.withPropertyValues("spring.graphql.schema.location:classpath:books/schema.graphqls")
|
||||
.withUserConfiguration(CustomGraphQLBuilderConfiguration.class)
|
||||
.withUserConfiguration(CustomGraphQlBuilderConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasBean("customGraphQLSourceBuilder");
|
||||
assertThat(context).hasSingleBean(GraphQLSource.Builder.class);
|
||||
assertThat(context).hasBean("customGraphQlSourceBuilder");
|
||||
assertThat(context).hasSingleBean(GraphQlSource.Builder.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomGraphQLBuilderConfiguration {
|
||||
static class CustomGraphQlBuilderConfiguration {
|
||||
|
||||
@Bean
|
||||
public GraphQLSource.Builder customGraphQLSourceBuilder() {
|
||||
return GraphQLSource.builder().schemaResource(new ClassPathResource("books/schema.graphqls"));
|
||||
public GraphQlSource.Builder customGraphQlSourceBuilder() {
|
||||
return GraphQlSource.builder().schemaResource(new ClassPathResource("books/schema.graphqls"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.List;
|
||||
import graphql.schema.DataFetcher;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
public class GraphQLDataFetchers {
|
||||
public class GraphQlDataFetchers {
|
||||
|
||||
private static List<Book> books = Arrays.asList(
|
||||
new Book("book-1", "GraphQL for beginners", 100, "John GraphQL"),
|
||||
@@ -42,8 +42,8 @@ class WebFluxApplicationContextTests {
|
||||
private static final AutoConfigurations AUTO_CONFIGURATIONS = AutoConfigurations.of(
|
||||
HttpHandlerAutoConfiguration.class, WebFluxAutoConfiguration.class,
|
||||
CodecsAutoConfiguration.class, JacksonAutoConfiguration.class,
|
||||
GraphQLAutoConfiguration.class, GraphQLServiceAutoConfiguration.class,
|
||||
WebFluxGraphQLAutoConfiguration.class);
|
||||
GraphQlAutoConfiguration.class, GraphQlServiceAutoConfiguration.class,
|
||||
WebFluxGraphQlAutoConfiguration.class);
|
||||
|
||||
private static final String BASE_URL = "https://spring.example.org/graphql";
|
||||
|
||||
@@ -141,7 +141,7 @@ class WebFluxApplicationContextTests {
|
||||
public RuntimeWiringCustomizer bookDataFetcher() {
|
||||
return (runtimeWiring) ->
|
||||
runtimeWiring.type(newTypeWiring("Query")
|
||||
.dataFetcher("bookById", GraphQLDataFetchers.getBookByIdDataFetcher()));
|
||||
.dataFetcher("bookById", GraphQlDataFetchers.getBookByIdDataFetcher()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static graphql.schema.idl.TypeRuntimeWiring.newTypeWiring;
|
||||
@@ -50,11 +49,11 @@ class WebMvcApplicationContextTests {
|
||||
public static final AutoConfigurations AUTO_CONFIGURATIONS = AutoConfigurations.of(
|
||||
DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class, JacksonAutoConfiguration.class,
|
||||
GraphQLAutoConfiguration.class, GraphQLServiceAutoConfiguration.class,
|
||||
WebMvcGraphQLAutoConfiguration.class);
|
||||
GraphQlAutoConfiguration.class, GraphQlServiceAutoConfiguration.class,
|
||||
WebMvcGraphQlAutoConfiguration.class);
|
||||
|
||||
@Test
|
||||
void endpointHandlesGraphQLQuery() {
|
||||
void endpointHandlesGraphQlQuery() {
|
||||
testWith(mockMvc -> {
|
||||
String query = "{" +
|
||||
" bookById(id: \\\"book-1\\\"){ " +
|
||||
@@ -139,7 +138,7 @@ class WebMvcApplicationContextTests {
|
||||
@Bean
|
||||
public RuntimeWiringCustomizer bookDataFetcher() {
|
||||
return (builder) -> builder.type(newTypeWiring("Query")
|
||||
.dataFetcher("bookById", GraphQLDataFetchers.getBookByIdDataFetcher()));
|
||||
.dataFetcher("bookById", GraphQlDataFetchers.getBookByIdDataFetcher()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,21 +30,21 @@ import org.springframework.graphql.test.tester.TestExecutionResult;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link GraphQLTags}
|
||||
* Tests for {@link GraphQlTags}
|
||||
*
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
class GraphQLTagsTests {
|
||||
class GraphQlTagsTests {
|
||||
|
||||
@Test
|
||||
void executionOutcomeShouldSucceed() {
|
||||
Tag outcomeTag = GraphQLTags.executionOutcome(new TestExecutionResult(), null);
|
||||
Tag outcomeTag = GraphQlTags.executionOutcome(new TestExecutionResult(), null);
|
||||
assertThat(outcomeTag.getValue()).isEqualTo("SUCCESS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void executionOutcomeShouldErrorWhenExceptionThrown() {
|
||||
Tag outcomeTag = GraphQLTags.executionOutcome(new TestExecutionResult(), new IllegalArgumentException("test error"));
|
||||
Tag outcomeTag = GraphQlTags.executionOutcome(new TestExecutionResult(), new IllegalArgumentException("test error"));
|
||||
assertThat(outcomeTag.getValue()).isEqualTo("ERROR");
|
||||
}
|
||||
|
||||
@@ -52,40 +52,40 @@ class GraphQLTagsTests {
|
||||
void executionOutcomeShouldErrorWhenResponseErrors() {
|
||||
ExecutionResultImpl.Builder builder = new ExecutionResultImpl.Builder();
|
||||
builder.addError(GraphqlErrorBuilder.newError().message("Invalid query").build());
|
||||
Tag outcomeTag = GraphQLTags.executionOutcome(builder.build(), null);
|
||||
Tag outcomeTag = GraphQlTags.executionOutcome(builder.build(), null);
|
||||
assertThat(outcomeTag.getValue()).isEqualTo("ERROR");
|
||||
}
|
||||
|
||||
@Test
|
||||
void errorTypeShouldBeDefinedIfPresent() {
|
||||
GraphQLError error = GraphqlErrorBuilder.newError().errorType(ErrorType.DataFetchingException).message("test error").build();
|
||||
Tag errorTypeTag = GraphQLTags.errorType(error);
|
||||
Tag errorTypeTag = GraphQlTags.errorType(error);
|
||||
assertThat(errorTypeTag.getValue()).isEqualTo("DataFetchingException");
|
||||
}
|
||||
|
||||
@Test
|
||||
void errorPathShouldUseJsonPathFormat() {
|
||||
GraphQLError error = GraphqlErrorBuilder.newError().path(Arrays.asList("project", "name")).message("test error").build();
|
||||
Tag errorPathTag = GraphQLTags.errorPath(error);
|
||||
Tag errorPathTag = GraphQlTags.errorPath(error);
|
||||
assertThat(errorPathTag.getValue()).isEqualTo("$.project.name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void errorPathShouldUseJsonPathFormatForIndices() {
|
||||
GraphQLError error = GraphqlErrorBuilder.newError().path(Arrays.asList("issues", "42", "title")).message("test error").build();
|
||||
Tag errorPathTag = GraphQLTags.errorPath(error);
|
||||
Tag errorPathTag = GraphQlTags.errorPath(error);
|
||||
assertThat(errorPathTag.getValue()).isEqualTo("$.issues[*].title");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dataFetchingOutcomeShouldBeSuccessfulIfNoException() {
|
||||
Tag fetchingOutcomeTag = GraphQLTags.dataFetchingOutcome(null);
|
||||
Tag fetchingOutcomeTag = GraphQlTags.dataFetchingOutcome(null);
|
||||
assertThat(fetchingOutcomeTag.getValue()).isEqualTo("SUCCESS");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dataFetchingOutcomeShouldBeErrorIfException() {
|
||||
Tag fetchingOutcomeTag = GraphQLTags.dataFetchingOutcome(new IllegalStateException("error state"));
|
||||
Tag fetchingOutcomeTag = GraphQlTags.dataFetchingOutcome(new IllegalStateException("error state"));
|
||||
assertThat(fetchingOutcomeTag.getValue()).isEqualTo("ERROR");
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.test.tester.GraphQLTester;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.test.tester.GraphQlTester;
|
||||
|
||||
/**
|
||||
* GraphQL query tests directly via {@link GraphQL}.
|
||||
@@ -30,19 +30,19 @@ import org.springframework.graphql.test.tester.GraphQLTester;
|
||||
@SpringBootTest
|
||||
public class QueryTests {
|
||||
|
||||
private GraphQLTester graphQLTester;
|
||||
private GraphQlTester graphQlTester;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(@Autowired WebGraphQLHandler handler) {
|
||||
this.graphQLTester = GraphQLTester.create(webInput ->
|
||||
public void setUp(@Autowired WebGraphQlHandler handler) {
|
||||
this.graphQlTester = GraphQlTester.create(webInput ->
|
||||
handler.handle(webInput).contextWrite(context -> context.put("name", "James")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void greetingMono() {
|
||||
this.graphQLTester.query("{greetingMono}")
|
||||
this.graphQlTester.query("{greetingMono}")
|
||||
.execute()
|
||||
.path("greetingMono")
|
||||
.entity(String.class)
|
||||
@@ -51,7 +51,7 @@ public class QueryTests {
|
||||
|
||||
@Test
|
||||
void greetingsFlux() {
|
||||
this.graphQLTester.query("{greetingsFlux}")
|
||||
this.graphQlTester.query("{greetingsFlux}")
|
||||
.execute()
|
||||
.path("greetingsFlux")
|
||||
.entityList(String.class)
|
||||
|
||||
@@ -23,8 +23,8 @@ import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.test.tester.GraphQLTester;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.test.tester.GraphQlTester;
|
||||
|
||||
/**
|
||||
* GraphQL subscription tests directly via {@link GraphQL}.
|
||||
@@ -32,12 +32,12 @@ import org.springframework.graphql.test.tester.GraphQLTester;
|
||||
@SpringBootTest
|
||||
public class SubscriptionTests {
|
||||
|
||||
private GraphQLTester graphQLTester;
|
||||
private GraphQlTester graphQlTester;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(@Autowired WebGraphQLHandler handler) {
|
||||
this.graphQLTester = GraphQLTester.create(webInput ->
|
||||
public void setUp(@Autowired WebGraphQlHandler handler) {
|
||||
this.graphQlTester = GraphQlTester.create(webInput ->
|
||||
handler.handle(webInput).contextWrite(context -> context.put("name", "James")));
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class SubscriptionTests {
|
||||
void subscriptionWithEntityPath() {
|
||||
String query = "subscription { greetings }";
|
||||
|
||||
Flux<String> result = this.graphQLTester.query(query)
|
||||
Flux<String> result = this.graphQlTester.query(query)
|
||||
.executeSubscription()
|
||||
.toFlux("greetings", String.class);
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SubscriptionTests {
|
||||
void subscriptionWithResponseSpec() {
|
||||
String query = "subscription { greetings }";
|
||||
|
||||
Flux<GraphQLTester.ResponseSpec> result = this.graphQLTester.query(query)
|
||||
Flux<GraphQlTester.ResponseSpec> result = this.graphQlTester.query(query)
|
||||
.executeSubscription()
|
||||
.toFlux();
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.test.tester.GraphQLTester;
|
||||
import org.springframework.graphql.test.tester.GraphQlTester;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
|
||||
@@ -33,15 +33,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
public class MockMvcGraphQLTests {
|
||||
public class MockMvcGraphQlTests {
|
||||
|
||||
private GraphQLTester graphQLTester;
|
||||
private GraphQlTester graphQlTester;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp(@Autowired MockMvc mockMvc) {
|
||||
WebTestClient client = MockMvcWebTestClient.bindTo(mockMvc).baseUrl("/graphql").build();
|
||||
this.graphQLTester = GraphQLTester.create(client);
|
||||
this.graphQlTester = GraphQlTester.create(client);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class MockMvcGraphQLTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
this.graphQLTester.query(query)
|
||||
this.graphQlTester.query(query)
|
||||
.execute()
|
||||
.path("project.releases[*].version")
|
||||
.entityList(String.class)
|
||||
@@ -71,7 +71,7 @@ public class MockMvcGraphQLTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
this.graphQLTester.query(query)
|
||||
this.graphQlTester.query(query)
|
||||
.execute()
|
||||
.path("project")
|
||||
.matchesJson("{\"repositoryUrl\":\"http://github.com/spring-projects/spring-framework\"}");
|
||||
@@ -87,7 +87,7 @@ public class MockMvcGraphQLTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
this.graphQLTester.query(query)
|
||||
this.graphQlTester.query(query)
|
||||
.execute()
|
||||
.path("project")
|
||||
.entity(Project.class)
|
||||
@@ -43,7 +43,7 @@ import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.RequestInput;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInput;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -60,14 +60,14 @@ import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link GraphQLTester}.
|
||||
* Default implementation of {@link GraphQlTester}.
|
||||
*/
|
||||
class DefaultGraphQLTester implements GraphQLTester {
|
||||
class DefaultGraphQlTester implements GraphQlTester {
|
||||
|
||||
private static final boolean jackson2Present;
|
||||
|
||||
static {
|
||||
ClassLoader classLoader = DefaultGraphQLTester.class.getClassLoader();
|
||||
ClassLoader classLoader = DefaultGraphQlTester.class.getClassLoader();
|
||||
jackson2Present = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) &&
|
||||
ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader);
|
||||
}
|
||||
@@ -78,12 +78,12 @@ class DefaultGraphQLTester implements GraphQLTester {
|
||||
private final Configuration jsonPathConfig;
|
||||
|
||||
|
||||
DefaultGraphQLTester(WebTestClient client) {
|
||||
DefaultGraphQlTester(WebTestClient client) {
|
||||
this.jsonPathConfig = initJsonPathConfig();
|
||||
this.requestStrategy = new WebTestClientRequestStrategy(client, this.jsonPathConfig);
|
||||
}
|
||||
|
||||
DefaultGraphQLTester(WebGraphQLHandler handler) {
|
||||
DefaultGraphQlTester(WebGraphQlHandler handler) {
|
||||
this.jsonPathConfig = initJsonPathConfig();
|
||||
this.requestStrategy = new DirectRequestStrategy(handler, this.jsonPathConfig);
|
||||
}
|
||||
@@ -107,12 +107,12 @@ class DefaultGraphQLTester implements GraphQLTester {
|
||||
/**
|
||||
* Perform a request with the given {@link RequestInput} container.
|
||||
*/
|
||||
GraphQLTester.ResponseSpec execute(RequestInput input);
|
||||
GraphQlTester.ResponseSpec execute(RequestInput input);
|
||||
|
||||
/**
|
||||
* Perform a subscription with the given {@link RequestInput} container.
|
||||
*/
|
||||
GraphQLTester.SubscriptionSpec executeSubscription(RequestInput input);
|
||||
GraphQlTester.SubscriptionSpec executeSubscription(RequestInput input);
|
||||
|
||||
}
|
||||
|
||||
@@ -182,12 +182,12 @@ class DefaultGraphQLTester implements GraphQLTester {
|
||||
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(5);
|
||||
|
||||
|
||||
private final WebGraphQLHandler graphQLHandler;
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
|
||||
private final Configuration jsonPathConfig;
|
||||
|
||||
public DirectRequestStrategy(WebGraphQLHandler handler, Configuration jsonPathConfig) {
|
||||
this.graphQLHandler = handler;
|
||||
public DirectRequestStrategy(WebGraphQlHandler handler, Configuration jsonPathConfig) {
|
||||
this.graphQlHandler = handler;
|
||||
this.jsonPathConfig = jsonPathConfig;
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ class DefaultGraphQLTester implements GraphQLTester {
|
||||
|
||||
private ExecutionResult executeInternal(RequestInput input) {
|
||||
WebInput webInput = new WebInput(DEFAULT_URL, DEFAULT_HEADERS, input.toMap(), null);
|
||||
ExecutionResult result = this.graphQLHandler.handle(webInput).block(DEFAULT_TIMEOUT);
|
||||
ExecutionResult result = this.graphQlHandler.handle(webInput).block(DEFAULT_TIMEOUT);
|
||||
Assert.notNull(result, "Expected ExecutionResult");
|
||||
return result;
|
||||
}
|
||||
@@ -269,20 +269,20 @@ class DefaultGraphQLTester implements GraphQLTester {
|
||||
@Override
|
||||
public ResponseSpec execute() {
|
||||
RequestInput input = new RequestInput(this.query, this.operationName, this.variables);
|
||||
return DefaultGraphQLTester.this.requestStrategy.execute(input);
|
||||
return DefaultGraphQlTester.this.requestStrategy.execute(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeAndVerify() {
|
||||
RequestInput input = new RequestInput(this.query, this.operationName, this.variables);
|
||||
ResponseSpec spec = DefaultGraphQLTester.this.requestStrategy.execute(input);
|
||||
ResponseSpec spec = DefaultGraphQlTester.this.requestStrategy.execute(input);
|
||||
spec.path("$.errors").valueIsEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubscriptionSpec executeSubscription() {
|
||||
RequestInput input = new RequestInput(this.query, this.operationName, this.variables);
|
||||
return DefaultGraphQLTester.this.requestStrategy.executeSubscription(input);
|
||||
return DefaultGraphQlTester.this.requestStrategy.executeSubscription(input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,11 +291,11 @@ class DefaultGraphQLTester implements GraphQLTester {
|
||||
|
||||
private static final Predicate<GraphQLError> MATCH_ALL_PREDICATE = error -> true;
|
||||
|
||||
private final List<TestGraphQLError> errors;
|
||||
private final List<TestGraphQlError> errors;
|
||||
|
||||
private final Consumer<Runnable> assertDecorator;
|
||||
|
||||
ErrorsContainer(List<TestGraphQLError> errors, Consumer<Runnable> assertDecorator) {
|
||||
ErrorsContainer(List<TestGraphQlError> errors, Consumer<Runnable> assertDecorator) {
|
||||
Assert.notNull(errors, "`errors` is required");
|
||||
Assert.notNull(assertDecorator, "`assertDecorator` is required");
|
||||
this.errors = errors;
|
||||
@@ -317,7 +317,7 @@ class DefaultGraphQLTester implements GraphQLTester {
|
||||
|
||||
public void verifyErrors() {
|
||||
|
||||
List<TestGraphQLError> unexpected =
|
||||
List<TestGraphQlError> unexpected =
|
||||
this.errors.stream().filter(error -> !error.isExpected()).collect(Collectors.toList());
|
||||
|
||||
this.assertDecorator.accept(() -> AssertionErrors.assertTrue(
|
||||
@@ -346,10 +346,10 @@ class DefaultGraphQLTester implements GraphQLTester {
|
||||
this.jsonContent = this.documentContext.jsonString();
|
||||
}
|
||||
|
||||
private static List<TestGraphQLError> readErrors(DocumentContext documentContext) {
|
||||
private static List<TestGraphQlError> readErrors(DocumentContext documentContext) {
|
||||
Assert.notNull(documentContext, "DocumentContext is required");
|
||||
try {
|
||||
return documentContext.read(ERRORS_PATH, new TypeRef<List<TestGraphQLError>>() {});
|
||||
return documentContext.read(ERRORS_PATH, new TypeRef<List<TestGraphQlError>>() {});
|
||||
}
|
||||
catch (PathNotFoundException ex) {
|
||||
return Collections.emptyList();
|
||||
@@ -24,14 +24,14 @@ import graphql.GraphQLError;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
* Main entry point for testing GraphQL with requests performed either as an
|
||||
* HTTP client via {@link WebTestClient} or directly via a
|
||||
* {@link WebGraphQLHandler}.
|
||||
* {@link WebGraphQlHandler}.
|
||||
*
|
||||
*
|
||||
* <p>GraphQL requests to Spring MVC without an HTTP server:
|
||||
@@ -40,12 +40,12 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
* @AutoConfigureMockMvc
|
||||
* public class MyTests {
|
||||
*
|
||||
* private GraphQLTester graphQLTester;
|
||||
* private GraphQlTester graphQlTester;
|
||||
*
|
||||
* @BeforeEach
|
||||
* public void setUp(@Autowired MockMvc mockMvc) {
|
||||
* WebTestClient client = MockMvcWebTestClient.bindTo(mockMvc).baseUrl("/graphql").build();
|
||||
* this.graphQLTester = GraphQLTester.create(client);
|
||||
* this.graphQlTester = GraphQlTester.create(client);
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -55,11 +55,11 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
* @AutoConfigureWebTestClient
|
||||
* public class MyTests {
|
||||
*
|
||||
* private GraphQLTester graphQLTester;
|
||||
* private GraphQlTester graphQlTester;
|
||||
*
|
||||
* @BeforeEach
|
||||
* public void setUp(@Autowired WebTestClient client) {
|
||||
* this.graphQLTester = GraphQLTester.create(client);
|
||||
* this.graphQlTester = GraphQlTester.create(client);
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
@@ -68,28 +68,28 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
* @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
* public class MyTests {
|
||||
*
|
||||
* private GraphQLTester graphQLTester;
|
||||
* private GraphQlTester graphQlTester;
|
||||
*
|
||||
* @BeforeEach
|
||||
* public void setUp(@Autowired WebTestClient client) {
|
||||
* this.graphQLTester = GraphQLTester.create(client);
|
||||
* this.graphQlTester = GraphQlTester.create(client);
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p>GraphQL requests to any {@link WebGraphQLHandler}:
|
||||
* <p>GraphQL requests to any {@link WebGraphQlHandler}:
|
||||
* <pre class="code">
|
||||
* @SpringBootTest
|
||||
* public class MyTests {
|
||||
*
|
||||
* private GraphQLTester graphQLTester;
|
||||
* private GraphQlTester graphQlTester;
|
||||
*
|
||||
* @BeforeEach
|
||||
* public void setUp(@Autowired WebGraphQLHandler handler) {
|
||||
* this.graphQLTester = GraphQLTester.create(handler);
|
||||
* this.graphQlTester = GraphQlTester.create(handler);
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
public interface GraphQLTester {
|
||||
public interface GraphQlTester {
|
||||
|
||||
/**
|
||||
* Prepare to perform a GraphQL request with the given operation which may
|
||||
@@ -102,25 +102,25 @@ public interface GraphQLTester {
|
||||
|
||||
|
||||
/**
|
||||
* Create a {@code GraphQLTester} that performs GraphQL requests as an HTTP
|
||||
* Create a {@code GraphQlTester} that performs GraphQL requests as an HTTP
|
||||
* client through the given {@link WebTestClient}. Depending on how the
|
||||
* {@code WebTestClient} is set up, tests may be with or without a server.
|
||||
* See setup examples in class-level Javadoc.
|
||||
* @param client the web client to perform requests with
|
||||
* @return the created {@code GraphQLTester} instance
|
||||
* @return the created {@code GraphQlTester} instance
|
||||
*/
|
||||
static GraphQLTester create(WebTestClient client) {
|
||||
return new DefaultGraphQLTester(client);
|
||||
static GraphQlTester create(WebTestClient client) {
|
||||
return new DefaultGraphQlTester(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@code GraphQLTester} that performs GraphQL requests through
|
||||
* the given {@link WebGraphQLHandler}.
|
||||
* Create a {@code GraphQlTester} that performs GraphQL requests through
|
||||
* the given {@link WebGraphQlHandler}.
|
||||
* @param handler the handler to execute requests with
|
||||
* @return the created {@code GraphQLTester} instance
|
||||
* @return the created {@code GraphQlTester} instance
|
||||
*/
|
||||
static GraphQLTester create(WebGraphQLHandler handler) {
|
||||
return new DefaultGraphQLTester(handler);
|
||||
static GraphQlTester create(WebGraphQlHandler handler) {
|
||||
return new DefaultGraphQlTester(handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class TestExecutionResult implements ExecutionResult {
|
||||
return (T) this.data;
|
||||
}
|
||||
|
||||
public void setErrors(List<TestGraphQLError> errors) {
|
||||
public void setErrors(List<TestGraphQlError> errors) {
|
||||
this.errors = new ArrayList<>(errors);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import graphql.language.SourceLocation;
|
||||
/**
|
||||
* {@link GraphQLError} with setters to use for deserialization.
|
||||
*/
|
||||
class TestGraphQLError implements GraphQLError {
|
||||
class TestGraphQlError implements GraphQLError {
|
||||
|
||||
private String message;
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInput;
|
||||
import org.springframework.graphql.web.WebOutput;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -55,34 +55,34 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link GraphQLTester} parameterized to:
|
||||
* Tests for {@link GraphQlTester} parameterized to:
|
||||
* <ul>
|
||||
* <li>Connect to {@link MockWebServer} and return a preset HTTP response.
|
||||
* <li>Use mock {@link WebGraphQLHandler} to return a preset {@link ExecutionResult}.
|
||||
* <li>Use mock {@link WebGraphQlHandler} to return a preset {@link ExecutionResult}.
|
||||
* </ul>
|
||||
*
|
||||
* <p>There is no actual handling via {@link graphql.GraphQL} in either scenario.
|
||||
* The main focus is to verify {@link GraphQLTester} request preparation and
|
||||
* The main focus is to verify {@link GraphQlTester} request preparation and
|
||||
* response handling.
|
||||
*/
|
||||
public class GraphQLTesterTests {
|
||||
public class GraphQlTesterTests {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
|
||||
public static Stream<GraphQLTesterSetup> argumentSource() {
|
||||
return Stream.of(new MockWebServerSetup(), new MockWebGraphQLHandlerSetup());
|
||||
public static Stream<GraphQlTesterSetup> argumentSource() {
|
||||
return Stream.of(new MockWebServerSetup(), new MockWebGraphQlHandlerSetup());
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void pathAndValueExistsAndEmptyChecks(GraphQLTesterSetup setup) throws Exception {
|
||||
void pathAndValueExistsAndEmptyChecks(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name, friends}}";
|
||||
setup.response("{\"me\": {\"name\":\"Luke Skywalker\", \"friends\":[]}}");
|
||||
|
||||
GraphQLTester.ResponseSpec spec = setup.graphQLTester().query(query).execute();
|
||||
GraphQlTester.ResponseSpec spec = setup.graphQlTester().query(query).execute();
|
||||
|
||||
spec.path("me.name").pathExists().valueExists().valueIsNotEmpty();
|
||||
spec.path("me.friends").valueIsEmpty();
|
||||
@@ -94,12 +94,12 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void matchesJson(GraphQLTesterSetup setup) throws Exception {
|
||||
void matchesJson(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name}}";
|
||||
setup.response("{\"me\": {\"name\":\"Luke Skywalker\", \"friends\":[]}}");
|
||||
|
||||
GraphQLTester.ResponseSpec spec = setup.graphQLTester().query(query).execute();
|
||||
GraphQlTester.ResponseSpec spec = setup.graphQlTester().query(query).execute();
|
||||
|
||||
spec.path("").matchesJson("{\"me\": {\"name\":\"Luke Skywalker\",\"friends\":[]}}");
|
||||
spec.path("me").matchesJson("{\"name\":\"Luke Skywalker\"}");
|
||||
@@ -115,12 +115,12 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void entity(GraphQLTesterSetup setup) throws Exception {
|
||||
void entity(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name}}";
|
||||
setup.response("{\"me\": {\"name\":\"Luke Skywalker\"}}");
|
||||
|
||||
GraphQLTester.ResponseSpec spec = setup.graphQLTester().query(query).execute();
|
||||
GraphQlTester.ResponseSpec spec = setup.graphQlTester().query(query).execute();
|
||||
|
||||
MovieCharacter luke = MovieCharacter.create("Luke Skywalker");
|
||||
MovieCharacter han = MovieCharacter.create("Han Solo");
|
||||
@@ -147,7 +147,7 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void entityList(GraphQLTesterSetup setup) throws Exception {
|
||||
void entityList(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name, friends}}";
|
||||
setup.response("{" +
|
||||
@@ -158,7 +158,7 @@ public class GraphQLTesterTests {
|
||||
"}"
|
||||
);
|
||||
|
||||
GraphQLTester.ResponseSpec spec = setup.graphQLTester().query(query).execute();
|
||||
GraphQlTester.ResponseSpec spec = setup.graphQlTester().query(query).execute();
|
||||
|
||||
MovieCharacter han = MovieCharacter.create("Han Solo");
|
||||
MovieCharacter leia = MovieCharacter.create("Leia Organa");
|
||||
@@ -185,7 +185,7 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void operationNameAndVariables(GraphQLTesterSetup setup) throws Exception {
|
||||
void operationNameAndVariables(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "query HeroNameAndFriends($episode: Episode) {" +
|
||||
" hero(episode: $episode) {" +
|
||||
@@ -195,7 +195,7 @@ public class GraphQLTesterTests {
|
||||
|
||||
setup.response("{\"hero\": {\"name\":\"R2-D2\"}}");
|
||||
|
||||
GraphQLTester.ResponseSpec spec = setup.graphQLTester().query(query)
|
||||
GraphQlTester.ResponseSpec spec = setup.graphQlTester().query(query)
|
||||
.operationName("HeroNameAndFriends")
|
||||
.variable("episode", "JEDI")
|
||||
.variables(map -> map.put("foo", "bar"))
|
||||
@@ -215,12 +215,12 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void errorsCheckedOnExecuteAndVerify(GraphQLTesterSetup setup) throws Exception {
|
||||
void errorsCheckedOnExecuteAndVerify(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name, friends}}";
|
||||
setup.response(GraphqlErrorBuilder.newError().message("Invalid query").build());
|
||||
|
||||
assertThatThrownBy(() -> setup.graphQLTester().query(query).executeAndVerify())
|
||||
assertThatThrownBy(() -> setup.graphQlTester().query(query).executeAndVerify())
|
||||
.hasMessageContaining("Response has 1 unexpected error(s).");
|
||||
|
||||
setup.verifyRequest(input -> assertThat(input.getQuery()).contains(query));
|
||||
@@ -229,12 +229,12 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void errorsCheckedOnTraverse(GraphQLTesterSetup setup) throws Exception {
|
||||
void errorsCheckedOnTraverse(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name, friends}}";
|
||||
setup.response(GraphqlErrorBuilder.newError().message("Invalid query").build());
|
||||
|
||||
assertThatThrownBy(() -> setup.graphQLTester().query(query).execute().path("me"))
|
||||
assertThatThrownBy(() -> setup.graphQlTester().query(query).execute().path("me"))
|
||||
.hasMessageContaining("Response has 1 unexpected error(s).");
|
||||
|
||||
setup.verifyRequest(input -> assertThat(input.getQuery()).contains(query));
|
||||
@@ -243,7 +243,7 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void errorsPartiallyFiltered(GraphQLTesterSetup setup) throws Exception {
|
||||
void errorsPartiallyFiltered(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name, friends}}";
|
||||
setup.response(
|
||||
@@ -251,7 +251,7 @@ public class GraphQLTesterTests {
|
||||
GraphqlErrorBuilder.newError().message("some other error").build());
|
||||
|
||||
assertThatThrownBy(() ->
|
||||
setup.graphQLTester().query(query).execute()
|
||||
setup.graphQlTester().query(query).execute()
|
||||
.errors()
|
||||
.filter(error -> error.getMessage().equals("some error"))
|
||||
.verify())
|
||||
@@ -263,14 +263,14 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void errorsFiltered(GraphQLTesterSetup setup) throws Exception {
|
||||
void errorsFiltered(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name, friends}}";
|
||||
setup.response(
|
||||
GraphqlErrorBuilder.newError().message("some error").build(),
|
||||
GraphqlErrorBuilder.newError().message("some other error").build());
|
||||
|
||||
setup.graphQLTester().query(query).execute()
|
||||
setup.graphQlTester().query(query).execute()
|
||||
.errors()
|
||||
.filter(error -> error.getMessage().startsWith("some "))
|
||||
.verify()
|
||||
@@ -282,7 +282,7 @@ public class GraphQLTesterTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("argumentSource")
|
||||
void errorsConsumed(GraphQLTesterSetup setup) throws Exception {
|
||||
void errorsConsumed(GraphQlTesterSetup setup) throws Exception {
|
||||
|
||||
String query = "{me {name, friends}}";
|
||||
setup.response(GraphqlErrorBuilder.newError()
|
||||
@@ -290,7 +290,7 @@ public class GraphQLTesterTests {
|
||||
.location(new SourceLocation(1, 2))
|
||||
.build());
|
||||
|
||||
setup.graphQLTester().query(query).execute()
|
||||
setup.graphQlTester().query(query).execute()
|
||||
.errors().satisfy(errors -> {
|
||||
assertThat(errors).hasSize(1);
|
||||
assertThat(errors.get(0).getMessage()).isEqualTo("Invalid query");
|
||||
@@ -305,9 +305,9 @@ public class GraphQLTesterTests {
|
||||
}
|
||||
|
||||
|
||||
private interface GraphQLTesterSetup {
|
||||
private interface GraphQlTesterSetup {
|
||||
|
||||
GraphQLTester graphQLTester();
|
||||
GraphQlTester graphQlTester();
|
||||
|
||||
default void response(String data) throws Exception {
|
||||
response(data, Collections.emptyList());
|
||||
@@ -328,15 +328,15 @@ public class GraphQLTesterTests {
|
||||
}
|
||||
|
||||
|
||||
private static class MockWebServerSetup implements GraphQLTesterSetup {
|
||||
private static class MockWebServerSetup implements GraphQlTesterSetup {
|
||||
|
||||
private final MockWebServer server;
|
||||
|
||||
private final GraphQLTester graphQLTester;
|
||||
private final GraphQlTester graphQlTester;
|
||||
|
||||
MockWebServerSetup() {
|
||||
this.server = new MockWebServer();
|
||||
this.graphQLTester = GraphQLTester.create(initWebTestClient(this.server));
|
||||
this.graphQlTester = GraphQlTester.create(initWebTestClient(this.server));
|
||||
}
|
||||
|
||||
private static WebTestClient initWebTestClient(MockWebServer server) {
|
||||
@@ -345,8 +345,8 @@ public class GraphQLTesterTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQLTester graphQLTester() {
|
||||
return this.graphQLTester;
|
||||
public GraphQlTester graphQlTester() {
|
||||
return this.graphQlTester;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -393,21 +393,21 @@ public class GraphQLTesterTests {
|
||||
}
|
||||
|
||||
|
||||
private static class MockWebGraphQLHandlerSetup implements GraphQLTesterSetup {
|
||||
private static class MockWebGraphQlHandlerSetup implements GraphQlTesterSetup {
|
||||
|
||||
private final WebGraphQLHandler handler = mock(WebGraphQLHandler.class);
|
||||
private final WebGraphQlHandler handler = mock(WebGraphQlHandler.class);
|
||||
|
||||
private final ArgumentCaptor<WebInput> bodyCaptor = ArgumentCaptor.forClass(WebInput.class);
|
||||
|
||||
private final GraphQLTester graphQLTester;
|
||||
private final GraphQlTester graphQlTester;
|
||||
|
||||
public MockWebGraphQLHandlerSetup() {
|
||||
this.graphQLTester = GraphQLTester.create(this.handler);
|
||||
public MockWebGraphQlHandlerSetup() {
|
||||
this.graphQlTester = GraphQlTester.create(this.handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQLTester graphQLTester() {
|
||||
return this.graphQLTester;
|
||||
public GraphQlTester graphQlTester() {
|
||||
return this.graphQlTester;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,7 +23,7 @@ import reactor.core.publisher.Mono;
|
||||
* Strategy to perform GraphQL request execution with input for and output from
|
||||
* the invocation of {@link graphql.GraphQL}.
|
||||
*/
|
||||
public interface GraphQLService {
|
||||
public interface GraphQlService {
|
||||
|
||||
/**
|
||||
* Perform the operation and return the result.
|
||||
@@ -37,11 +37,11 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link GraphQLSource.Builder} that initializes a
|
||||
* {@link GraphQL} instance and wraps it with a {@link GraphQLSource} that
|
||||
* Default implementation of {@link GraphQlSource.Builder} that initializes a
|
||||
* {@link GraphQL} instance and wraps it with a {@link GraphQlSource} that
|
||||
* returns it.
|
||||
*/
|
||||
class DefaultGraphQLSourceBuilder implements GraphQLSource.Builder {
|
||||
class DefaultGraphQlSourceBuilder implements GraphQlSource.Builder {
|
||||
|
||||
@Nullable
|
||||
private Resource schemaResource;
|
||||
@@ -54,53 +54,53 @@ class DefaultGraphQLSourceBuilder implements GraphQLSource.Builder {
|
||||
|
||||
private final List<Instrumentation> instrumentations = new ArrayList<>();
|
||||
|
||||
private Consumer<GraphQL.Builder> graphQLConfigurers = builder -> {};
|
||||
private Consumer<GraphQL.Builder> graphQlConfigurers = builder -> {};
|
||||
|
||||
|
||||
DefaultGraphQLSourceBuilder() {
|
||||
DefaultGraphQlSourceBuilder() {
|
||||
this.typeVisitors.add(ReactorDataFetcherAdapter.TYPE_VISITOR);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GraphQLSource.Builder schemaResource(Resource resource) {
|
||||
public GraphQlSource.Builder schemaResource(Resource resource) {
|
||||
this.schemaResource = resource;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQLSource.Builder runtimeWiring(RuntimeWiring runtimeWiring) {
|
||||
public GraphQlSource.Builder runtimeWiring(RuntimeWiring runtimeWiring) {
|
||||
Assert.notNull(runtimeWiring, "RuntimeWiring is required");
|
||||
this.runtimeWiring = runtimeWiring;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQLSource.Builder exceptionResolvers(List<DataFetcherExceptionResolver> resolvers) {
|
||||
public GraphQlSource.Builder exceptionResolvers(List<DataFetcherExceptionResolver> resolvers) {
|
||||
this.exceptionResolvers.addAll(resolvers);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQLSource.Builder typeVisitors(List<GraphQLTypeVisitor> typeVisitors) {
|
||||
public GraphQlSource.Builder typeVisitors(List<GraphQLTypeVisitor> typeVisitors) {
|
||||
this.typeVisitors.addAll(typeVisitors);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQLSource.Builder instrumentation(List<Instrumentation> instrumentations) {
|
||||
public GraphQlSource.Builder instrumentation(List<Instrumentation> instrumentations) {
|
||||
this.instrumentations.addAll(instrumentations);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQLSource.Builder configureGraphQL(Consumer<GraphQL.Builder> configurer) {
|
||||
this.graphQLConfigurers = this.graphQLConfigurers.andThen(configurer);
|
||||
public GraphQlSource.Builder configureGraphQl(Consumer<GraphQL.Builder> configurer) {
|
||||
this.graphQlConfigurers = this.graphQlConfigurers.andThen(configurer);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQLSource build() {
|
||||
public GraphQlSource build() {
|
||||
TypeDefinitionRegistry registry = parseSchemaResource();
|
||||
|
||||
GraphQLSchema schema = new SchemaGenerator().makeExecutableSchema(registry, this.runtimeWiring);
|
||||
@@ -113,10 +113,10 @@ class DefaultGraphQLSourceBuilder implements GraphQLSource.Builder {
|
||||
if (!this.instrumentations.isEmpty()) {
|
||||
builder = builder.instrumentation(new ChainedInstrumentation(this.instrumentations));
|
||||
}
|
||||
this.graphQLConfigurers.accept(builder);
|
||||
GraphQL graphQL = builder.build();
|
||||
this.graphQlConfigurers.accept(builder);
|
||||
GraphQL graphQl = builder.build();
|
||||
|
||||
return new CachedGraphQLSource(graphQL, schema);
|
||||
return new CachedGraphQlSource(graphQl, schema);
|
||||
}
|
||||
|
||||
private TypeDefinitionRegistry parseSchemaResource() {
|
||||
@@ -135,22 +135,22 @@ class DefaultGraphQLSourceBuilder implements GraphQLSource.Builder {
|
||||
|
||||
|
||||
/**
|
||||
* GraphQLSource that returns the built GraphQL instance and its schema.
|
||||
* GraphQlSource that returns the built GraphQL instance and its schema.
|
||||
*/
|
||||
private static class CachedGraphQLSource implements GraphQLSource {
|
||||
private static class CachedGraphQlSource implements GraphQlSource {
|
||||
|
||||
private final GraphQL graphQL;
|
||||
private final GraphQL graphQl;
|
||||
|
||||
private final GraphQLSchema schema;
|
||||
|
||||
CachedGraphQLSource(GraphQL graphQL, GraphQLSchema schema) {
|
||||
this.graphQL = graphQL;
|
||||
CachedGraphQlSource(GraphQL graphQl, GraphQLSchema schema) {
|
||||
this.graphQl = graphQl;
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQL graphQL() {
|
||||
return this.graphQL;
|
||||
public GraphQL graphQl() {
|
||||
return this.graphQl;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -20,28 +20,28 @@ import graphql.ExecutionResult;
|
||||
import graphql.GraphQL;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.GraphQLService;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
|
||||
/**
|
||||
* Implementation of {@link GraphQLService} that performs GraphQL request execution
|
||||
* Implementation of {@link GraphQlService} that performs GraphQL request execution
|
||||
* through {@link GraphQL#executeAsync(ExecutionInput)}.
|
||||
*/
|
||||
public class ExecutionGraphQLService implements GraphQLService {
|
||||
public class ExecutionGraphQlService implements GraphQlService {
|
||||
|
||||
private final GraphQLSource graphQLSource;
|
||||
private final GraphQlSource graphQlSource;
|
||||
|
||||
|
||||
public ExecutionGraphQLService(GraphQLSource graphQLSource) {
|
||||
this.graphQLSource = graphQLSource;
|
||||
public ExecutionGraphQlService(GraphQlSource graphQlSource) {
|
||||
this.graphQlSource = graphQlSource;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<ExecutionResult> execute(ExecutionInput input) {
|
||||
GraphQL graphQL = this.graphQLSource.graphQL();
|
||||
GraphQL graphQl = this.graphQlSource.graphQl();
|
||||
return Mono.deferContextual(contextView -> {
|
||||
ReactorDataFetcherAdapter.addReactorContext(input, contextView);
|
||||
return Mono.fromFuture(graphQL.executeAsync(input));
|
||||
return Mono.fromFuture(graphQl.executeAsync(input));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,18 +31,18 @@ import org.springframework.core.io.Resource;
|
||||
/**
|
||||
* Strategy to resolve the {@link GraphQL} instance to use.
|
||||
*
|
||||
* <p>This contract also includes a {@link GraphQLSource} builder encapsulating
|
||||
* <p>This contract also includes a {@link GraphQlSource} builder encapsulating
|
||||
* the initialization of the {@link GraphQL} instance and associated
|
||||
* {@link graphql.schema.GraphQLSchema}.
|
||||
*/
|
||||
public interface GraphQLSource {
|
||||
public interface GraphQlSource {
|
||||
|
||||
|
||||
/**
|
||||
* Return the {@link GraphQL} to use. This can be a cached instance or a
|
||||
* different one from time to time (e.g. based on a reloaded schema).
|
||||
*/
|
||||
GraphQL graphQL();
|
||||
GraphQL graphQl();
|
||||
|
||||
/**
|
||||
* Return the {@link GraphQLSchema} used by the current {@link GraphQL}.
|
||||
@@ -51,16 +51,16 @@ public interface GraphQLSource {
|
||||
|
||||
|
||||
/**
|
||||
* Return a builder for a {@link GraphQLSource} given input for the
|
||||
* Return a builder for a {@link GraphQlSource} given input for the
|
||||
* initialization of {@link GraphQL} and {@link graphql.schema.GraphQLSchema}.
|
||||
*/
|
||||
static Builder builder() {
|
||||
return new DefaultGraphQLSourceBuilder();
|
||||
return new DefaultGraphQlSourceBuilder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builder for a {@link GraphQLSource}.
|
||||
* Builder for a {@link GraphQlSource}.
|
||||
*/
|
||||
interface Builder {
|
||||
|
||||
@@ -101,12 +101,12 @@ public interface GraphQLSource {
|
||||
* Configure consumers to be given access to the {@link GraphQL.Builder}
|
||||
* used to build {@link GraphQL}.
|
||||
*/
|
||||
Builder configureGraphQL(Consumer<GraphQL.Builder> configurer);
|
||||
Builder configureGraphQl(Consumer<GraphQL.Builder> configurer);
|
||||
|
||||
/**
|
||||
* Build the {@link GraphQLSource}.
|
||||
* Build the {@link GraphQlSource}.
|
||||
*/
|
||||
GraphQLSource build();
|
||||
GraphQlSource build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -89,8 +89,8 @@ class ReactorDataFetcherAdapter implements DataFetcher<Object> {
|
||||
|
||||
@Nullable
|
||||
private ContextView getReactorContext(DataFetchingEnvironment environment) {
|
||||
GraphQLContext graphQLContext = environment.getContext();
|
||||
return graphQLContext.get(REACTOR_CONTEXT_KEY);
|
||||
GraphQLContext graphQlContext = environment.getContext();
|
||||
return graphQlContext.get(REACTOR_CONTEXT_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,8 +98,8 @@ class ReactorDataFetcherAdapter implements DataFetcher<Object> {
|
||||
* for later retrieval from the {@link DataFetchingEnvironment}.
|
||||
*/
|
||||
public static void addReactorContext(ExecutionInput executionInput, ContextView reactorContext) {
|
||||
GraphQLContext graphQLContext = (GraphQLContext) executionInput.getContext();
|
||||
graphQLContext.put(REACTOR_CONTEXT_KEY, reactorContext);
|
||||
GraphQLContext graphQlContext = (GraphQLContext) executionInput.getContext();
|
||||
graphQlContext.put(REACTOR_CONTEXT_KEY, reactorContext);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Top level abstractions for processing GraphQL requests including
|
||||
* {@link org.springframework.graphql.GraphQLService} for executing a request and
|
||||
* {@link org.springframework.graphql.GraphQlService} for executing a request and
|
||||
* {@link org.springframework.graphql.RequestInput} to represent the input for
|
||||
* a request.
|
||||
*/
|
||||
|
||||
@@ -19,15 +19,15 @@ import java.util.List;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.GraphQLService;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
|
||||
/**
|
||||
* Contract to handle a GraphQL over HTTP or WebSocket request that forms the
|
||||
* basis of a {@link WebInterceptor} delegation chain.
|
||||
*
|
||||
* @see WebInterceptor#createHandler(List, GraphQLService)
|
||||
* @see WebInterceptor#createHandler(List, GraphQlService)
|
||||
*/
|
||||
public interface WebGraphQLHandler {
|
||||
public interface WebGraphQlHandler {
|
||||
|
||||
/**
|
||||
* Perform request execution for the given input and return the result.
|
||||
@@ -22,7 +22,7 @@ import graphql.ExecutionResult;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.graphql.GraphQLService;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -40,14 +40,14 @@ public interface WebInterceptor {
|
||||
|
||||
/**
|
||||
* Intercept a request and delegate for further handling and request execution
|
||||
* via {@link WebGraphQLHandler#handle(WebInput)}.
|
||||
* via {@link WebGraphQlHandler#handle(WebInput)}.
|
||||
*
|
||||
* @param webInput container with HTTP request information and options to
|
||||
* customize the {@link ExecutionInput}.
|
||||
* @param next the handler to delegate to for request execution
|
||||
* @return a {@link Mono} with the result
|
||||
*/
|
||||
Mono<WebOutput> intercept(WebInput webInput, WebGraphQLHandler next);
|
||||
Mono<WebOutput> intercept(WebInput webInput, WebGraphQlHandler next);
|
||||
|
||||
/**
|
||||
* Return a composed {@link WebInterceptor} that invokes the current
|
||||
@@ -59,21 +59,21 @@ public interface WebInterceptor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@link WebGraphQLHandler} that invokes the current interceptor
|
||||
* first and then the given {@link GraphQLService} for actual execution of
|
||||
* Return {@link WebGraphQlHandler} that invokes the current interceptor
|
||||
* first and then the given {@link GraphQlService} for actual execution of
|
||||
* the GraphQL operation.
|
||||
*/
|
||||
default WebGraphQLHandler apply(GraphQLService service) {
|
||||
Assert.notNull(service, "GraphQLService must not be null");
|
||||
default WebGraphQlHandler apply(GraphQlService service) {
|
||||
Assert.notNull(service, "GraphQlService must not be null");
|
||||
return currentInput -> intercept(currentInput, createHandler(service));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory method for a {@link WebGraphQLHandler} with a chain of
|
||||
* interceptors followed by a {@link GraphQLService} at the end.
|
||||
* Factory method for a {@link WebGraphQlHandler} with a chain of
|
||||
* interceptors followed by a {@link GraphQlService} at the end.
|
||||
*/
|
||||
static WebGraphQLHandler createHandler(List<WebInterceptor> interceptors, GraphQLService service) {
|
||||
static WebGraphQlHandler createHandler(List<WebInterceptor> interceptors, GraphQlService service) {
|
||||
return interceptors.stream()
|
||||
.reduce(WebInterceptor::andThen)
|
||||
.map(interceptor -> interceptor.apply(service))
|
||||
@@ -81,14 +81,14 @@ public interface WebInterceptor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for a {@link WebGraphQLHandler} that simple invokes the
|
||||
* given {@link GraphQLService} adapting to its input and output.
|
||||
* Factory method for a {@link WebGraphQlHandler} that simple invokes the
|
||||
* given {@link GraphQlService} adapting to its input and output.
|
||||
*/
|
||||
static WebGraphQLHandler createHandler(GraphQLService graphQLService) {
|
||||
Assert.notNull(graphQLService, "GraphQLService must not be null");
|
||||
static WebGraphQlHandler createHandler(GraphQlService graphQlService) {
|
||||
Assert.notNull(graphQlService, "GraphQlService must not be null");
|
||||
return webInput -> {
|
||||
ExecutionInput executionInput = webInput.toExecutionInput();
|
||||
return graphQLService.execute(executionInput).map(result -> new WebOutput(webInput, result));
|
||||
return graphQlService.execute(executionInput).map(result -> new WebOutput(webInput, result));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInput;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
@@ -31,24 +31,24 @@ import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
/**
|
||||
* WebFlux.fn Handler for GraphQL over HTTP requests.
|
||||
*/
|
||||
public class GraphQLHttpHandler {
|
||||
public class GraphQlHttpHandler {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GraphQLHttpHandler.class);
|
||||
private static final Log logger = LogFactory.getLog(GraphQlHttpHandler.class);
|
||||
|
||||
private static final ParameterizedTypeReference<Map<String, Object>> MAP_PARAMETERIZED_TYPE_REF =
|
||||
new ParameterizedTypeReference<Map<String, Object>>() {};
|
||||
|
||||
|
||||
private final WebGraphQLHandler graphQLHandler;
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param graphQLHandler common handler for GraphQL over HTTP requests
|
||||
* @param graphQlHandler common handler for GraphQL over HTTP requests
|
||||
*/
|
||||
public GraphQLHttpHandler(WebGraphQLHandler graphQLHandler) {
|
||||
Assert.notNull(graphQLHandler, "WebGraphQLHandler is required");
|
||||
this.graphQLHandler = graphQLHandler;
|
||||
public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler) {
|
||||
Assert.notNull(graphQlHandler, "WebGraphQlHandler is required");
|
||||
this.graphQlHandler = graphQlHandler;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public class GraphQLHttpHandler {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing: " + input);
|
||||
}
|
||||
return this.graphQLHandler.handle(input);
|
||||
return this.graphQlHandler.handle(input);
|
||||
})
|
||||
.flatMap(output -> {
|
||||
Map<String, Object> spec = output.toSpecification();
|
||||
@@ -39,7 +39,7 @@ import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInput;
|
||||
import org.springframework.graphql.web.WebOutput;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -61,9 +61,9 @@ import org.springframework.web.reactive.socket.WebSocketSession;
|
||||
* <a href="https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md">GraphQL Over WebSocket Protocol</a>
|
||||
* and for use in a Spring WebFlux application.
|
||||
*/
|
||||
public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
public class GraphQlWebSocketHandler implements WebSocketHandler {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GraphQLWebSocketHandler.class);
|
||||
private static final Log logger = LogFactory.getLog(GraphQlWebSocketHandler.class);
|
||||
|
||||
private static final List<String> SUB_PROTOCOL_LIST =
|
||||
Arrays.asList("graphql-transport-ws", "subscriptions-transport-ws");
|
||||
@@ -72,7 +72,7 @@ public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
ResolvableType.forType(new ParameterizedTypeReference<Map<String, Object>>() {});
|
||||
|
||||
|
||||
private final WebGraphQLHandler graphQLHandler;
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
|
||||
private final Decoder<?> decoder;
|
||||
|
||||
@@ -83,16 +83,16 @@ public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param graphQLHandler common handler for GraphQL over HTTP requests
|
||||
* @param graphQlHandler common handler for GraphQL over HTTP requests
|
||||
* @param configurer codec configurer for JSON encoding and decoding
|
||||
* @param connectionInitTimeout the time within which the {@code CONNECTION_INIT}
|
||||
* type message must be received.
|
||||
*/
|
||||
public GraphQLWebSocketHandler(
|
||||
WebGraphQLHandler graphQLHandler, ServerCodecConfigurer configurer, Duration connectionInitTimeout) {
|
||||
public GraphQlWebSocketHandler(
|
||||
WebGraphQlHandler graphQlHandler, ServerCodecConfigurer configurer, Duration connectionInitTimeout) {
|
||||
|
||||
Assert.notNull(graphQLHandler, "WebGraphQLHandler is required");
|
||||
this.graphQLHandler = graphQLHandler;
|
||||
Assert.notNull(graphQlHandler, "WebGraphQlHandler is required");
|
||||
this.graphQlHandler = graphQlHandler;
|
||||
this.decoder = initDecoder(configurer);
|
||||
this.encoder = initEncoder(configurer);
|
||||
this.initTimeoutDuration = connectionInitTimeout;
|
||||
@@ -129,7 +129,7 @@ public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
logger.debug("apollographql/subscriptions-transport-ws is not supported, nor maintained. " +
|
||||
"Please, use https://github.com/enisdenjo/graphql-ws.");
|
||||
}
|
||||
return session.close(GraphQLStatus.INVALID_MESSAGE_STATUS);
|
||||
return session.close(GraphQlStatus.INVALID_MESSAGE_STATUS);
|
||||
}
|
||||
|
||||
// Session state
|
||||
@@ -139,7 +139,7 @@ public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
Mono.delay(this.initTimeoutDuration)
|
||||
.then(Mono.defer(() ->
|
||||
connectionInitProcessed.compareAndSet(false, true) ?
|
||||
session.close(GraphQLStatus.INIT_TIMEOUT_STATUS) :
|
||||
session.close(GraphQlStatus.INIT_TIMEOUT_STATUS) :
|
||||
Mono.empty()))
|
||||
.subscribe();
|
||||
|
||||
@@ -149,22 +149,22 @@ public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
String id = (String) map.get("id");
|
||||
MessageType messageType = MessageType.resolve((String) map.get("type"));
|
||||
if (messageType == null) {
|
||||
return GraphQLStatus.close(session, GraphQLStatus.INVALID_MESSAGE_STATUS);
|
||||
return GraphQlStatus.close(session, GraphQlStatus.INVALID_MESSAGE_STATUS);
|
||||
}
|
||||
switch (messageType) {
|
||||
case SUBSCRIBE:
|
||||
if (!connectionInitProcessed.get()) {
|
||||
return GraphQLStatus.close(session, GraphQLStatus.UNAUTHORIZED_STATUS);
|
||||
return GraphQlStatus.close(session, GraphQlStatus.UNAUTHORIZED_STATUS);
|
||||
}
|
||||
if (id == null) {
|
||||
return GraphQLStatus.close(session, GraphQLStatus.INVALID_MESSAGE_STATUS);
|
||||
return GraphQlStatus.close(session, GraphQlStatus.INVALID_MESSAGE_STATUS);
|
||||
}
|
||||
WebInput input = new WebInput(
|
||||
handshakeInfo.getUri(), handshakeInfo.getHeaders(), getPayload(map), id);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing: " + input);
|
||||
}
|
||||
return this.graphQLHandler.handle(input)
|
||||
return this.graphQlHandler.handle(input)
|
||||
.flatMapMany(output -> handleWebOutput(session, id, subscriptions, output))
|
||||
.doOnTerminate(() -> subscriptions.remove(id));
|
||||
case COMPLETE:
|
||||
@@ -177,11 +177,11 @@ public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
return Flux.empty();
|
||||
case CONNECTION_INIT:
|
||||
if (!connectionInitProcessed.compareAndSet(false, true)) {
|
||||
return GraphQLStatus.close(session, GraphQLStatus.TOO_MANY_INIT_REQUESTS_STATUS);
|
||||
return GraphQlStatus.close(session, GraphQlStatus.TOO_MANY_INIT_REQUESTS_STATUS);
|
||||
}
|
||||
return Flux.just(encode(session, null, MessageType.CONNECTION_ACK, null));
|
||||
default:
|
||||
return GraphQLStatus.close(session, GraphQLStatus.INVALID_MESSAGE_STATUS);
|
||||
return GraphQlStatus.close(session, GraphQlStatus.INVALID_MESSAGE_STATUS);
|
||||
}
|
||||
}));
|
||||
}
|
||||
@@ -236,7 +236,7 @@ public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
.onErrorResume(ex -> {
|
||||
if (ex instanceof SubscriptionExistsException) {
|
||||
CloseStatus status = new CloseStatus(4409, "Subscriber for " + id + " already exists");
|
||||
return GraphQLStatus.close(session, status);
|
||||
return GraphQlStatus.close(session, status);
|
||||
}
|
||||
ErrorType errorType = ErrorType.DataFetchingException;
|
||||
String message = ex.getMessage();
|
||||
@@ -306,7 +306,7 @@ public class GraphQLWebSocketHandler implements WebSocketHandler {
|
||||
}
|
||||
|
||||
|
||||
private static class GraphQLStatus {
|
||||
private static class GraphQlStatus {
|
||||
|
||||
static final CloseStatus INVALID_MESSAGE_STATUS = new CloseStatus(4400, "Invalid message");
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInput;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
||||
@@ -37,24 +37,24 @@ import org.springframework.web.servlet.function.ServerResponse;
|
||||
* GraphQL handler to expose as a WebMvc.fn endpoint via
|
||||
* {@link org.springframework.web.servlet.function.RouterFunctions}.
|
||||
*/
|
||||
public class GraphQLHttpHandler {
|
||||
public class GraphQlHttpHandler {
|
||||
|
||||
private final static Log logger = LogFactory.getLog(GraphQLHttpHandler.class);
|
||||
private final static Log logger = LogFactory.getLog(GraphQlHttpHandler.class);
|
||||
|
||||
private static final ParameterizedTypeReference<Map<String, Object>> MAP_PARAMETERIZED_TYPE_REF =
|
||||
new ParameterizedTypeReference<Map<String, Object>>() {};
|
||||
|
||||
|
||||
private final WebGraphQLHandler graphQLHandler;
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param graphQLHandler common handler for GraphQL over HTTP requests
|
||||
* @param graphQlHandler common handler for GraphQL over HTTP requests
|
||||
*/
|
||||
public GraphQLHttpHandler(WebGraphQLHandler graphQLHandler) {
|
||||
Assert.notNull(graphQLHandler, "WebGraphQLHandler is required");
|
||||
this.graphQLHandler = graphQLHandler;
|
||||
public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler) {
|
||||
Assert.notNull(graphQlHandler, "WebGraphQlHandler is required");
|
||||
this.graphQlHandler = graphQlHandler;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ public class GraphQLHttpHandler {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing: " + input);
|
||||
}
|
||||
Mono<ServerResponse> responseMono = this.graphQLHandler.handle(input)
|
||||
Mono<ServerResponse> responseMono = this.graphQlHandler.handle(input)
|
||||
.map(output -> {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Execution complete");
|
||||
@@ -41,7 +41,7 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInput;
|
||||
import org.springframework.graphql.web.WebOutput;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -63,15 +63,15 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
* <a href="https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md">GraphQL Over WebSocket Protocol</a>
|
||||
* and for use on a Servlet container with {@code spring-websocket}.
|
||||
*/
|
||||
public class GraphQLWebSocketHandler extends TextWebSocketHandler implements SubProtocolCapable {
|
||||
public class GraphQlWebSocketHandler extends TextWebSocketHandler implements SubProtocolCapable {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(GraphQLWebSocketHandler.class);
|
||||
private static final Log logger = LogFactory.getLog(GraphQlWebSocketHandler.class);
|
||||
|
||||
private static final List<String> SUB_PROTOCOL_LIST =
|
||||
Arrays.asList("graphql-transport-ws", "subscriptions-transport-ws");
|
||||
|
||||
|
||||
private final WebGraphQLHandler graphQLHandler;
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
|
||||
private final Duration initTimeoutDuration;
|
||||
|
||||
@@ -82,17 +82,17 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param graphQLHandler common handler for GraphQL over HTTP requests
|
||||
* @param graphQlHandler common handler for GraphQL over HTTP requests
|
||||
* @param converter for JSON encoding and decoding
|
||||
* @param connectionInitTimeout the time within which the {@code CONNECTION_INIT}
|
||||
* type message must be received.
|
||||
*/
|
||||
public GraphQLWebSocketHandler(
|
||||
WebGraphQLHandler graphQLHandler, HttpMessageConverter<?> converter, Duration connectionInitTimeout) {
|
||||
public GraphQlWebSocketHandler(
|
||||
WebGraphQlHandler graphQlHandler, HttpMessageConverter<?> converter, Duration connectionInitTimeout) {
|
||||
|
||||
Assert.notNull(graphQLHandler, "WebGraphQLHandler is required");
|
||||
Assert.notNull(graphQlHandler, "WebGraphQlHandler is required");
|
||||
Assert.notNull(converter, "HttpMessageConverter for JSON is required");
|
||||
this.graphQLHandler = graphQLHandler;
|
||||
this.graphQlHandler = graphQlHandler;
|
||||
this.initTimeoutDuration = connectionInitTimeout;
|
||||
this.converter = converter;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub
|
||||
logger.debug("apollographql/subscriptions-transport-ws is not supported, nor maintained. " +
|
||||
"Please, use https://github.com/enisdenjo/graphql-ws.");
|
||||
}
|
||||
GraphQLStatus.closeSession(session, GraphQLStatus.INVALID_MESSAGE_STATUS);
|
||||
GraphQlStatus.closeSession(session, GraphQlStatus.INVALID_MESSAGE_STATUS);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub
|
||||
Mono.delay(this.initTimeoutDuration)
|
||||
.then(Mono.fromRunnable(() -> {
|
||||
if (sessionState.isConnectionInitNotProcessed()) {
|
||||
GraphQLStatus.closeSession(session, GraphQLStatus.INIT_TIMEOUT_STATUS);
|
||||
GraphQlStatus.closeSession(session, GraphQlStatus.INIT_TIMEOUT_STATUS);
|
||||
}
|
||||
}))
|
||||
.subscribe();
|
||||
@@ -134,18 +134,18 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub
|
||||
String id = (String) map.get("id");
|
||||
MessageType messageType = MessageType.resolve((String) map.get("type"));
|
||||
if (messageType == null) {
|
||||
GraphQLStatus.closeSession(session, GraphQLStatus.INVALID_MESSAGE_STATUS);
|
||||
GraphQlStatus.closeSession(session, GraphQlStatus.INVALID_MESSAGE_STATUS);
|
||||
return;
|
||||
}
|
||||
SessionState sessionState = getSessionInfo(session);
|
||||
switch (messageType) {
|
||||
case SUBSCRIBE:
|
||||
if (sessionState.isConnectionInitNotProcessed()) {
|
||||
GraphQLStatus.closeSession(session, GraphQLStatus.UNAUTHORIZED_STATUS);
|
||||
GraphQlStatus.closeSession(session, GraphQlStatus.UNAUTHORIZED_STATUS);
|
||||
return;
|
||||
}
|
||||
if (id == null) {
|
||||
GraphQLStatus.closeSession(session, GraphQLStatus.INVALID_MESSAGE_STATUS);
|
||||
GraphQlStatus.closeSession(session, GraphQlStatus.INVALID_MESSAGE_STATUS);
|
||||
return;
|
||||
}
|
||||
URI uri = session.getUri();
|
||||
@@ -155,7 +155,7 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing: " + input);
|
||||
}
|
||||
this.graphQLHandler.handle(input)
|
||||
this.graphQlHandler.handle(input)
|
||||
.flatMapMany(output -> handleWebOutput(session, input.getId(), output))
|
||||
.publishOn(sessionState.getScheduler()) // Serial blocking send via single thread
|
||||
.subscribe(new SendMessageSubscriber(id, session, sessionState));
|
||||
@@ -170,14 +170,14 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub
|
||||
return;
|
||||
case CONNECTION_INIT:
|
||||
if (sessionState.setConnectionInitProcessed()) {
|
||||
GraphQLStatus.closeSession(session, GraphQLStatus.TOO_MANY_INIT_REQUESTS_STATUS);
|
||||
GraphQlStatus.closeSession(session, GraphQlStatus.TOO_MANY_INIT_REQUESTS_STATUS);
|
||||
return;
|
||||
}
|
||||
TextMessage outputMessage = encode(null, MessageType.CONNECTION_ACK, null);
|
||||
session.sendMessage(outputMessage);
|
||||
return;
|
||||
default:
|
||||
GraphQLStatus.closeSession(session, GraphQLStatus.INVALID_MESSAGE_STATUS);
|
||||
GraphQlStatus.closeSession(session, GraphQlStatus.INVALID_MESSAGE_STATUS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -234,7 +234,7 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub
|
||||
.onErrorResume(ex -> {
|
||||
if (ex instanceof SubscriptionExistsException) {
|
||||
CloseStatus status = new CloseStatus(4409, "Subscriber for " + id + " already exists");
|
||||
GraphQLStatus.closeSession(session, status);
|
||||
GraphQlStatus.closeSession(session, status);
|
||||
return Flux.empty();
|
||||
}
|
||||
ErrorType errorType = ErrorType.DataFetchingException;
|
||||
@@ -326,7 +326,7 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub
|
||||
}
|
||||
|
||||
|
||||
private static class GraphQLStatus {
|
||||
private static class GraphQlStatus {
|
||||
|
||||
private static final CloseStatus INVALID_MESSAGE_STATUS = new CloseStatus(4400, "Invalid message");
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ExceptionResolversExceptionHandlerTests {
|
||||
|
||||
@Test
|
||||
void resolveException() throws Exception {
|
||||
GraphQL graphQL = graphQL("type Query { greeting: String }",
|
||||
GraphQL graphQl = graphQl("type Query { greeting: String }",
|
||||
"Query", "greeting", env -> {
|
||||
throw new IllegalArgumentException("Invalid greeting");
|
||||
},
|
||||
@@ -53,7 +53,7 @@ public class ExceptionResolversExceptionHandlerTests {
|
||||
.build()));
|
||||
|
||||
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
|
||||
ExecutionResult result = graphQL.executeAsync(input).get();
|
||||
ExecutionResult result = graphQl.executeAsync(input).get();
|
||||
|
||||
Map<String, Object> data = result.getData();
|
||||
assertThat(data).hasSize(1).containsEntry("greeting", null);
|
||||
@@ -67,13 +67,13 @@ public class ExceptionResolversExceptionHandlerTests {
|
||||
|
||||
@Test
|
||||
void unresolvedException() throws Exception {
|
||||
GraphQL graphQL = graphQL("type Query { greeting: String }",
|
||||
GraphQL graphQl = graphQl("type Query { greeting: String }",
|
||||
"Query", "greeting", env -> {
|
||||
throw new IllegalArgumentException("Invalid greeting");
|
||||
});
|
||||
|
||||
ExecutionInput input = ExecutionInput.newExecutionInput().query("{ greeting }").build();
|
||||
ExecutionResult result = graphQL.executeAsync(input).get();
|
||||
ExecutionResult result = graphQl.executeAsync(input).get();
|
||||
|
||||
Map<String, Object> data = result.getData();
|
||||
assertThat(data).hasSize(1).containsEntry("greeting", null);
|
||||
@@ -85,7 +85,7 @@ public class ExceptionResolversExceptionHandlerTests {
|
||||
assertThat(error.getErrorType().toString()).isEqualTo("INTERNAL_ERROR");
|
||||
}
|
||||
|
||||
private GraphQL graphQL(String schemaContent,
|
||||
private GraphQL graphQl(String schemaContent,
|
||||
String typeName, String fieldName, DataFetcher<?> dataFetcher,
|
||||
@Nullable DataFetcherExceptionResolver... resolvers) {
|
||||
|
||||
@@ -93,12 +93,12 @@ public class ExceptionResolversExceptionHandlerTests {
|
||||
.type(typeName, builder -> builder.dataFetcher(fieldName, dataFetcher))
|
||||
.build();
|
||||
|
||||
return GraphQLSource.builder()
|
||||
return GraphQlSource.builder()
|
||||
.schemaResource(new ByteArrayResource(schemaContent.getBytes(StandardCharsets.UTF_8)))
|
||||
.runtimeWiring(wiring)
|
||||
.exceptionResolvers(Arrays.asList(resolvers))
|
||||
.build()
|
||||
.graphQL();
|
||||
.graphQl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ReactorDataFetcherAdapterTests {
|
||||
|
||||
@Test
|
||||
void monoDataFetcher() throws Exception {
|
||||
GraphQL graphQL = graphQL("type Query { greeting: String }",
|
||||
GraphQL graphQl = graphQl("type Query { greeting: String }",
|
||||
"Query", "greeting", env ->
|
||||
Mono.deferContextual(context -> {
|
||||
Object name = context.get("name");
|
||||
@@ -50,14 +50,14 @@ public class ReactorDataFetcherAdapterTests {
|
||||
}));
|
||||
|
||||
ExecutionInput input = executionInput("{ greeting }", Context.of("name", "007"));
|
||||
Map<String, Object> data = graphQL.executeAsync(input).get().getData();
|
||||
Map<String, Object> data = graphQl.executeAsync(input).get().getData();
|
||||
|
||||
assertThat(data).hasSize(1).containsEntry("greeting", "Hello 007");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fluxDataFetcher() throws Exception {
|
||||
GraphQL graphQL = graphQL("type Query { greetings: [String] }",
|
||||
GraphQL graphQl = graphQl("type Query { greetings: [String] }",
|
||||
"Query", "greetings", env ->
|
||||
Mono.delay(Duration.ofMillis(50)).flatMapMany(aLong ->
|
||||
Flux.deferContextual(context -> {
|
||||
@@ -66,14 +66,14 @@ public class ReactorDataFetcherAdapterTests {
|
||||
})));
|
||||
|
||||
ExecutionInput input = executionInput("{ greetings }", Context.of("name", "007"));
|
||||
Map<String, Object> data = graphQL.executeAsync(input).get().getData();
|
||||
Map<String, Object> data = graphQl.executeAsync(input).get().getData();
|
||||
|
||||
assertThat((List<String>) data.get("greetings")).containsExactly("Hi 007", "Bonjour 007", "Hola 007");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fluxDataFetcherSubscription() throws Exception {
|
||||
GraphQL graphQL = graphQL(
|
||||
GraphQL graphQl = graphQl(
|
||||
"type Query { greeting: String } type Subscription { greetings: String }",
|
||||
"Subscription", "greetings", env ->
|
||||
Mono.delay(Duration.ofMillis(50)).flatMapMany(aLong ->
|
||||
@@ -83,7 +83,7 @@ public class ReactorDataFetcherAdapterTests {
|
||||
})));
|
||||
|
||||
ExecutionInput input = executionInput("subscription { greetings }", Context.of("name", "007"));
|
||||
Publisher<String> publisher = graphQL.executeAsync(input).get().getData();
|
||||
Publisher<String> publisher = graphQl.executeAsync(input).get().getData();
|
||||
|
||||
List<String> actual = Flux.from(publisher)
|
||||
.cast(ExecutionResult.class)
|
||||
@@ -95,15 +95,15 @@ public class ReactorDataFetcherAdapterTests {
|
||||
assertThat(actual).containsExactly("Hi 007", "Bonjour 007", "Hola 007");
|
||||
}
|
||||
|
||||
private GraphQL graphQL(String schemaValue, String typeName, String fieldName, DataFetcher<?> dataFetcher) {
|
||||
private GraphQL graphQl(String schemaValue, String typeName, String fieldName, DataFetcher<?> dataFetcher) {
|
||||
RuntimeWiring wiring = RuntimeWiring.newRuntimeWiring()
|
||||
.type(typeName, builder -> builder.dataFetcher(fieldName, dataFetcher))
|
||||
.build();
|
||||
return GraphQLSource.builder()
|
||||
return GraphQlSource.builder()
|
||||
.schemaResource(new ByteArrayResource(schemaValue.getBytes(StandardCharsets.UTF_8)))
|
||||
.runtimeWiring(wiring)
|
||||
.build()
|
||||
.graphQL();
|
||||
.graphQl();
|
||||
}
|
||||
|
||||
private ExecutionInput executionInput(String query, Context reactorContext) {
|
||||
|
||||
@@ -24,7 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class ConsumeOneAndNeverCompleteInterceptor implements WebInterceptor {
|
||||
|
||||
@Override
|
||||
public Mono<WebOutput> intercept(WebInput webInput, WebGraphQLHandler next) {
|
||||
public Mono<WebOutput> intercept(WebInput webInput, WebGraphQlHandler next) {
|
||||
return next.handle(webInput).map(output ->
|
||||
output.transform(builder -> {
|
||||
Publisher<?> publisher = output.getData();
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.List;
|
||||
import graphql.schema.DataFetcher;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
public class GraphQLDataFetchers {
|
||||
public class GraphQlDataFetchers {
|
||||
|
||||
private static List<Book> books = Arrays.asList(
|
||||
new Book("book-1", "GraphQL for beginners", 100, "John GraphQL"),
|
||||
@@ -22,7 +22,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import graphql.ExecutionInput;
|
||||
import graphql.ExecutionResult;
|
||||
import graphql.ExecutionResultImpl;
|
||||
@@ -30,7 +29,7 @@ import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import org.springframework.graphql.GraphQLService;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -46,7 +45,7 @@ public class WebInterceptorTests {
|
||||
List<WebInterceptor> interceptors = Arrays.asList(
|
||||
new TestWebInterceptor(sb, 1), new TestWebInterceptor(sb, 2), new TestWebInterceptor(sb, 3));
|
||||
|
||||
TestGraphQLService service = new TestGraphQLService();
|
||||
TestGraphQlService service = new TestGraphQlService();
|
||||
|
||||
WebInput input = new WebInput(
|
||||
URI.create("/"), new HttpHeaders(), Collections.singletonMap("query", "any"), "1");
|
||||
@@ -59,7 +58,7 @@ public class WebInterceptorTests {
|
||||
}
|
||||
|
||||
|
||||
private static class TestGraphQLService implements GraphQLService {
|
||||
private static class TestGraphQlService implements GraphQlService {
|
||||
|
||||
private ExecutionInput savedInput;
|
||||
|
||||
@@ -87,7 +86,7 @@ public class WebInterceptorTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<WebOutput> intercept(WebInput webInput, WebGraphQLHandler next) {
|
||||
public Mono<WebOutput> intercept(WebInput webInput, WebGraphQlHandler next) {
|
||||
|
||||
this.output.append(":pre").append(this.index);
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.graphql.execution.ExecutionGraphQLService;
|
||||
import org.springframework.graphql.execution.GraphQLSource;
|
||||
import org.springframework.graphql.execution.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.web.ConsumeOneAndNeverCompleteInterceptor;
|
||||
import org.springframework.graphql.web.GraphQLDataFetchers;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.GraphQlDataFetchers;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInterceptor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||
@@ -57,9 +57,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.map;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GraphQLWebSocketHandler}.
|
||||
* Unit tests for {@link GraphQlWebSocketHandler}.
|
||||
*/
|
||||
public class GraphQLWebSocketHandlerTests {
|
||||
public class GraphQlWebSocketHandlerTests {
|
||||
|
||||
private static final Jackson2JsonDecoder decoder = new Jackson2JsonDecoder();
|
||||
|
||||
@@ -267,29 +267,29 @@ public class GraphQLWebSocketHandlerTests {
|
||||
.verifyTimeout(Duration.ofMillis(500));
|
||||
}
|
||||
|
||||
private GraphQLWebSocketHandler initWebSocketHandler() throws Exception {
|
||||
private GraphQlWebSocketHandler initWebSocketHandler() throws Exception {
|
||||
return initWebSocketHandler(Collections.emptyList(), Duration.ofSeconds(60));
|
||||
}
|
||||
|
||||
private GraphQLWebSocketHandler initWebSocketHandler(
|
||||
private GraphQlWebSocketHandler initWebSocketHandler(
|
||||
@Nullable List<WebInterceptor> interceptors, @Nullable Duration initTimeoutDuration) throws Exception {
|
||||
|
||||
WebGraphQLHandler graphQLHandler = WebInterceptor.createHandler(
|
||||
WebGraphQlHandler graphQlHandler = WebInterceptor.createHandler(
|
||||
(interceptors != null ? interceptors : Collections.emptyList()),
|
||||
new ExecutionGraphQLService(graphQLSource()));
|
||||
new ExecutionGraphQlService(graphQlSource()));
|
||||
|
||||
return new GraphQLWebSocketHandler(graphQLHandler,
|
||||
return new GraphQlWebSocketHandler(graphQlHandler,
|
||||
ServerCodecConfigurer.create(),
|
||||
(initTimeoutDuration != null ? initTimeoutDuration : Duration.ofSeconds(60)));
|
||||
}
|
||||
|
||||
private static GraphQLSource graphQLSource() {
|
||||
private static GraphQlSource graphQlSource() {
|
||||
RuntimeWiring.Builder builder = RuntimeWiring.newRuntimeWiring();
|
||||
builder.type(newTypeWiring("Query").dataFetcher("bookById", GraphQLDataFetchers.getBookByIdDataFetcher()));
|
||||
builder.type(newTypeWiring("Subscription").dataFetcher("bookSearch", GraphQLDataFetchers.getBooksOnSale()));
|
||||
builder.type(newTypeWiring("Query").dataFetcher("bookById", GraphQlDataFetchers.getBookByIdDataFetcher()));
|
||||
builder.type(newTypeWiring("Subscription").dataFetcher("bookSearch", GraphQlDataFetchers.getBooksOnSale()));
|
||||
RuntimeWiring runtimeWiring = builder.build();
|
||||
|
||||
return GraphQLSource.builder()
|
||||
return GraphQlSource.builder()
|
||||
.schemaResource(new ClassPathResource("books/schema.graphqls"))
|
||||
.runtimeWiring(runtimeWiring)
|
||||
.build();
|
||||
@@ -304,7 +304,7 @@ public class GraphQLWebSocketHandlerTests {
|
||||
private Map<String, Object> decode(WebSocketMessage message) {
|
||||
return (Map<String, Object>) decoder.decode(
|
||||
DataBufferUtils.retain(message.getPayload()),
|
||||
GraphQLWebSocketHandler.MAP_RESOLVABLE_TYPE, null, Collections.emptyMap());
|
||||
GraphQlWebSocketHandler.MAP_RESOLVABLE_TYPE, null, Collections.emptyMap());
|
||||
}
|
||||
|
||||
private void assertMessageType(WebSocketMessage message, String messageType) {
|
||||
@@ -31,11 +31,11 @@ import org.junit.jupiter.api.Test;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.graphql.execution.ExecutionGraphQLService;
|
||||
import org.springframework.graphql.execution.GraphQLSource;
|
||||
import org.springframework.graphql.execution.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.execution.GraphQlSource;
|
||||
import org.springframework.graphql.web.ConsumeOneAndNeverCompleteInterceptor;
|
||||
import org.springframework.graphql.web.GraphQLDataFetchers;
|
||||
import org.springframework.graphql.web.WebGraphQLHandler;
|
||||
import org.springframework.graphql.web.GraphQlDataFetchers;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInterceptor;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
@@ -52,9 +52,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.map;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GraphQLWebSocketHandler}.
|
||||
* Unit tests for {@link GraphQlWebSocketHandler}.
|
||||
*/
|
||||
public class GraphQLWebSocketHandlerTests {
|
||||
public class GraphQlWebSocketHandlerTests {
|
||||
|
||||
private static final String SUBSCRIPTION_ID = "123";
|
||||
|
||||
@@ -76,7 +76,7 @@ public class GraphQLWebSocketHandlerTests {
|
||||
|
||||
private final TestWebSocketSession session = new TestWebSocketSession();
|
||||
|
||||
private final GraphQLWebSocketHandler handler =
|
||||
private final GraphQlWebSocketHandler handler =
|
||||
initWebSocketHandler(Collections.emptyList(), Duration.ofSeconds(60));
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ public class GraphQLWebSocketHandlerTests {
|
||||
|
||||
@Test
|
||||
void connectionInitTimeout() {
|
||||
GraphQLWebSocketHandler handler = initWebSocketHandler(Collections.emptyList(), Duration.ofMillis(50));
|
||||
GraphQlWebSocketHandler handler = initWebSocketHandler(Collections.emptyList(), Duration.ofMillis(50));
|
||||
handler.afterConnectionEstablished(session);
|
||||
|
||||
StepVerifier.create(session.closeStatus())
|
||||
@@ -202,7 +202,7 @@ public class GraphQLWebSocketHandlerTests {
|
||||
|
||||
@Test
|
||||
void subscriptionExists() throws Exception {
|
||||
GraphQLWebSocketHandler handler = initWebSocketHandler(
|
||||
GraphQlWebSocketHandler handler = initWebSocketHandler(
|
||||
Collections.singletonList(new ConsumeOneAndNeverCompleteInterceptor()), null);
|
||||
|
||||
handler.afterConnectionEstablished(session);
|
||||
@@ -225,7 +225,7 @@ public class GraphQLWebSocketHandlerTests {
|
||||
|
||||
@Test
|
||||
void clientCompletion() throws Exception {
|
||||
GraphQLWebSocketHandler handler = initWebSocketHandler(
|
||||
GraphQlWebSocketHandler handler = initWebSocketHandler(
|
||||
Collections.singletonList(new ConsumeOneAndNeverCompleteInterceptor()), null);
|
||||
|
||||
handler.afterConnectionEstablished(session);
|
||||
@@ -254,15 +254,15 @@ public class GraphQLWebSocketHandlerTests {
|
||||
}
|
||||
|
||||
|
||||
private GraphQLWebSocketHandler initWebSocketHandler(
|
||||
private GraphQlWebSocketHandler initWebSocketHandler(
|
||||
@Nullable List<WebInterceptor> interceptors, @Nullable Duration initTimeoutDuration) {
|
||||
|
||||
try {
|
||||
WebGraphQLHandler graphQLHandler = WebInterceptor.createHandler(
|
||||
WebGraphQlHandler graphQlHandler = WebInterceptor.createHandler(
|
||||
(interceptors != null ? interceptors : Collections.emptyList()),
|
||||
new ExecutionGraphQLService(graphQLSource()));
|
||||
new ExecutionGraphQlService(graphQlSource()));
|
||||
|
||||
return new GraphQLWebSocketHandler(graphQLHandler, converter,
|
||||
return new GraphQlWebSocketHandler(graphQlHandler, converter,
|
||||
(initTimeoutDuration != null ? initTimeoutDuration : Duration.ofSeconds(60)));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -270,13 +270,13 @@ public class GraphQLWebSocketHandlerTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static GraphQLSource graphQLSource() {
|
||||
private static GraphQlSource graphQlSource() {
|
||||
RuntimeWiring.Builder builder = RuntimeWiring.newRuntimeWiring();
|
||||
builder.type(newTypeWiring("Query").dataFetcher("bookById", GraphQLDataFetchers.getBookByIdDataFetcher()));
|
||||
builder.type(newTypeWiring("Subscription").dataFetcher("bookSearch", GraphQLDataFetchers.getBooksOnSale()));
|
||||
builder.type(newTypeWiring("Query").dataFetcher("bookById", GraphQlDataFetchers.getBookByIdDataFetcher()));
|
||||
builder.type(newTypeWiring("Subscription").dataFetcher("bookSearch", GraphQlDataFetchers.getBooksOnSale()));
|
||||
RuntimeWiring runtimeWiring = builder.build();
|
||||
|
||||
return GraphQLSource.builder()
|
||||
return GraphQlSource.builder()
|
||||
.schemaResource(new ClassPathResource("books/schema.graphqls"))
|
||||
.runtimeWiring(runtimeWiring)
|
||||
.build();
|
||||
Reference in New Issue
Block a user