From 44a034ef3d4a1b1b91cd23e6c919f4db9117ad28 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 12 May 2021 09:50:03 +0100 Subject: [PATCH] Refine use of "query" in type and method names Following revisions in the spec https://github.com/graphql/graphql-spec/pull/777, this commit applies similar changes to type and method names where feasible. The chief exception for now is the use of "query" for request input since that is what it is called in the JSON for GraphQL over HTTP. --- .../graphql/boot/GraphQLProperties.java | 2 +- .../boot/WebFluxGraphQLAutoConfiguration.java | 2 +- .../boot/WebMvcGraphQLAutoConfiguration.java | 6 ++--- .../test/tester/DefaultGraphQLTester.java | 24 +++++++++---------- .../graphql/test/tester/GraphQLTester.java | 21 ++++++++-------- .../graphql/GraphQLService.java | 6 ++--- .../springframework/graphql/RequestInput.java | 6 ++--- .../support/ExecutionGraphQLService.java | 2 +- .../graphql/web/WebGraphQLHandler.java | 4 ++-- .../springframework/graphql/web/WebInput.java | 2 +- .../graphql/web/WebInterceptor.java | 8 +++---- .../graphql/web/WebOutput.java | 4 ++-- .../web/webflux/GraphQLHttpHandler.java | 4 ++-- .../web/webflux/GraphQLWebSocketHandler.java | 2 +- .../web/webmvc/GraphQLHttpHandler.java | 2 +- .../web/webmvc/GraphQLWebSocketHandler.java | 2 +- 16 files changed, 49 insertions(+), 48 deletions(-) diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQLProperties.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQLProperties.java index eedc73d7..cc1fc121 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQLProperties.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/GraphQLProperties.java @@ -23,7 +23,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; public class GraphQLProperties { /** - * Path of the GraphQL HTTP query endpoint. + * Path at which to expose a GraphQL request HTTP endpoint. */ private String path = "/graphql"; diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphQLAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphQLAutoConfiguration.java index baee72cc..702b5935 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphQLAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebFluxGraphQLAutoConfiguration.java @@ -86,7 +86,7 @@ public class WebFluxGraphQLAutoConfiguration { } RouterFunctions.Builder builder = RouterFunctions.route() .GET(path, req -> ServerResponse.ok().bodyValue(resource)) - .POST(path, accept(MediaType.APPLICATION_JSON).and(contentType(MediaType.APPLICATION_JSON)), handler::handleQuery); + .POST(path, accept(MediaType.APPLICATION_JSON).and(contentType(MediaType.APPLICATION_JSON)), handler::handleRequest); if (properties.getSchema().getPrinter().isEnabled()) { SchemaPrinter schemaPrinter = new SchemaPrinter(); builder = builder.GET(path + properties.getSchema().getPrinter().getPath(), diff --git a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphQLAutoConfiguration.java b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphQLAutoConfiguration.java index 77616a37..9eb99688 100644 --- a/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphQLAutoConfiguration.java +++ b/graphql-spring-boot-starter/src/main/java/org/springframework/graphql/boot/WebMvcGraphQLAutoConfiguration.java @@ -83,7 +83,7 @@ public class WebMvcGraphQLAutoConfiguration { } @Bean - public RouterFunction graphQLQueryEndpoint(GraphQLHttpHandler handler, GraphQLSource graphQLSource, + public RouterFunction graphQLRouterFunction(GraphQLHttpHandler handler, GraphQLSource graphQLSource, GraphQLProperties properties, ResourceLoader resourceLoader) { String path = properties.getPath(); @@ -93,7 +93,7 @@ public class WebMvcGraphQLAutoConfiguration { } RouterFunctions.Builder builder = RouterFunctions.route() .GET(path, req -> ServerResponse.ok().body(resource)) - .POST(path, contentType(MediaType.APPLICATION_JSON).and(accept(MediaType.APPLICATION_JSON)), handler::handle); + .POST(path, contentType(MediaType.APPLICATION_JSON).and(accept(MediaType.APPLICATION_JSON)), handler::handleRequest); if (properties.getSchema().getPrinter().isEnabled()) { SchemaPrinter schemaPrinter = new SchemaPrinter(); builder = builder.GET(path + properties.getSchema().getPrinter().getPath(), @@ -122,7 +122,7 @@ public class WebMvcGraphQLAutoConfiguration { } @Bean - public HandlerMapping graphQLWebSocketEndpoint(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); diff --git a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQLTester.java b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQLTester.java index 2e4c615b..31ff4d8c 100644 --- a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQLTester.java +++ b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQLTester.java @@ -94,8 +94,8 @@ class DefaultGraphQLTester implements GraphQLTester { @Override - public QuerySpec query(String query) { - return new DefaultQuerySpec(query); + public RequestSpec query(String query) { + return new DefaultRequestSpec(query); } @@ -105,7 +105,7 @@ class DefaultGraphQLTester implements GraphQLTester { interface RequestStrategy { /** - * Perform a query with the given {@link RequestInput} container. + * Perform a request with the given {@link RequestInput} container. */ GraphQLTester.ResponseSpec execute(RequestInput input); @@ -153,11 +153,11 @@ class DefaultGraphQLTester implements GraphQLTester { } @Override - public SubscriptionSpec executeSubscription(RequestInput queryInput) { + public SubscriptionSpec executeSubscription(RequestInput requestInput) { FluxExchangeResult exchangeResult = this.client.post() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.TEXT_EVENT_STREAM) - .bodyValue(queryInput) + .bodyValue(requestInput) .exchange() .expectStatus().isOk() .expectHeader().contentType(MediaType.TEXT_EVENT_STREAM) @@ -224,7 +224,7 @@ class DefaultGraphQLTester implements GraphQLTester { assertion.run(); } catch (AssertionError ex) { - throw new AssertionError(ex.getMessage() + "\nQuery: " + input, ex); + throw new AssertionError(ex.getMessage() + "\nRequest: " + input, ex); } }; } @@ -232,9 +232,9 @@ class DefaultGraphQLTester implements GraphQLTester { /** - * {@link QuerySpec} that collects the query, operationName, and variables. + * {@link RequestSpec} that collects the query, operationName, and variables. */ - private class DefaultQuerySpec implements QuerySpec { + private class DefaultRequestSpec implements RequestSpec { private final String query; @@ -243,25 +243,25 @@ class DefaultGraphQLTester implements GraphQLTester { private final Map variables = new LinkedHashMap<>(); - private DefaultQuerySpec(String query) { + private DefaultRequestSpec(String query) { Assert.notNull(query, "`query` is required"); this.query = query; } @Override - public QuerySpec operationName(@Nullable String name) { + public RequestSpec operationName(@Nullable String name) { this.operationName = name; return this; } @Override - public QuerySpec variable(String name, Object value) { + public RequestSpec variable(String name, Object value) { this.variables.put(name, value); return this; } @Override - public QuerySpec variables(Consumer> variablesConsumer) { + public RequestSpec variables(Consumer> variablesConsumer) { variablesConsumer.accept(this.variables); return this; } diff --git a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/GraphQLTester.java b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/GraphQLTester.java index 21d51210..dbdf78ce 100644 --- a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/GraphQLTester.java +++ b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/GraphQLTester.java @@ -92,12 +92,13 @@ import org.springframework.test.web.reactive.server.WebTestClient; public interface GraphQLTester { /** - * Prepare to perform a GraphQL request with the given query. - * @param query the query to send + * Prepare to perform a GraphQL request with the given operation which may + * be a query, mutation, or a subscription. + * @param query the operation to be performed * @return spec for response assertions * @throws AssertionError if the response status is not 200 (OK) */ - QuerySpec query(String query); + RequestSpec query(String query); /** @@ -157,24 +158,24 @@ public interface GraphQLTester { /** - * Declare options to gather input for a GraphQL query and execute it. + * Declare options to gather input for a GraphQL request and execute it. */ - interface QuerySpec extends ExecuteSpec { + interface RequestSpec extends ExecuteSpec { /** * Set the operation name. */ - QuerySpec operationName(@Nullable String name); + RequestSpec operationName(@Nullable String name); /** * Add a variable. */ - QuerySpec variable(String name, Object value); + RequestSpec variable(String name, Object value); /** * Modify variables by accessing the underlying map. */ - QuerySpec variables(Consumer> variablesConsumer); + RequestSpec variables(Consumer> variablesConsumer); } @@ -185,8 +186,8 @@ public interface GraphQLTester { /** * Switch to a path under the "data" section of the GraphQL response. - * The path can be a query root type name, e.g. "project", or a nested - * path such as "project.name", or any + * The path can be an operation root type name, e.g. "project", or a + * nested path such as "project.name", or any * JsonPath. * * @param path the path to switch to diff --git a/spring-graphql/src/main/java/org/springframework/graphql/GraphQLService.java b/spring-graphql/src/main/java/org/springframework/graphql/GraphQLService.java index fae8401b..f38e611b 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/GraphQLService.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/GraphQLService.java @@ -20,14 +20,14 @@ import graphql.ExecutionResult; import reactor.core.publisher.Mono; /** - * Strategy to perform GraphQL query execution with input for and output from + * Strategy to perform GraphQL request execution with input for and output from * the invocation of {@link graphql.GraphQL}. */ public interface GraphQLService { /** - * Perform the query and return the result. - * @param input the input for query execution via {@link graphql.GraphQL} + * Perform the operation and return the result. + * @param input the input for the {@link graphql.GraphQL} invocation * @return the execution result */ Mono execute(ExecutionInput input); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java b/spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java index cbe32e8f..059b6e93 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/RequestInput.java @@ -69,7 +69,7 @@ public class RequestInput { } /** - * Return the query operation name extracted from the request body or + * Return the operation name extracted from the request body or * {@code null} if not provided. */ @Nullable @@ -78,7 +78,7 @@ public class RequestInput { } /** - * Return the query variables that can be referenced via $syntax extracted + * Return the variables that can be referenced via $syntax extracted * from the request body or a {@code null} if not provided. */ public Map getVariables() { @@ -98,7 +98,7 @@ public class RequestInput { } /** - * Create the {@link ExecutionInput} for query execution. This is initially + * Create the {@link ExecutionInput} for request execution. This is initially * populated from {@link #getQuery()}, {@link #getOperationName()}, and * {@link #getVariables()}, and is then further customized through * {@link #configureExecutionInput(BiFunction)}. diff --git a/spring-graphql/src/main/java/org/springframework/graphql/support/ExecutionGraphQLService.java b/spring-graphql/src/main/java/org/springframework/graphql/support/ExecutionGraphQLService.java index ab4a38e0..6e50ae06 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/support/ExecutionGraphQLService.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/support/ExecutionGraphQLService.java @@ -23,7 +23,7 @@ import reactor.core.publisher.Mono; import org.springframework.graphql.GraphQLService; /** - * Implementation of {@link GraphQLService} that performs GraphQL query execution + * Implementation of {@link GraphQLService} that performs GraphQL request execution * through {@link GraphQL#executeAsync(ExecutionInput)}. */ public class ExecutionGraphQLService implements GraphQLService { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQLHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQLHandler.java index fea98c23..c364fec1 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQLHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQLHandler.java @@ -30,9 +30,9 @@ import org.springframework.graphql.GraphQLService; public interface WebGraphQLHandler { /** - * Perform query execution for the given request and return the result. + * Perform request execution for the given input and return the result. * - * @param input the GraphQL query container + * @param input the GraphQL request input container * @return the execution result */ Mono handle(WebInput input); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/WebInput.java b/spring-graphql/src/main/java/org/springframework/graphql/web/WebInput.java index fd0950c1..3eb16d44 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/WebInput.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/WebInput.java @@ -71,7 +71,7 @@ public class WebInput extends RequestInput { /** * Return the URI of the HTTP request including - * {@link UriComponents#getQueryParams() query parameters}. + * {@link UriComponents#getQueryParams() URL query parameters}. */ public UriComponents getUri() { return this.uri; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/WebInterceptor.java b/spring-graphql/src/main/java/org/springframework/graphql/web/WebInterceptor.java index aeb0c71d..f2d552cc 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/WebInterceptor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/WebInterceptor.java @@ -29,7 +29,7 @@ import org.springframework.util.Assert; * Interceptor for intercepting GraphQL over HTTP or WebSocket requests. * Provides information about the HTTP request or WebSocket handshake, allows * customization of the {@link ExecutionInput} and of the {@link ExecutionResult} - * from query execution. + * from request execution. * *

Interceptors may be declared as beans in Spring configuration and ordered * as defined in {@link ObjectProvider#orderedStream()}. @@ -39,12 +39,12 @@ import org.springframework.util.Assert; public interface WebInterceptor { /** - * Intercept a request and delegate for further handling and query execution + * Intercept a request and delegate for further handling and request execution * 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 query execution + * @param next the handler to delegate to for request execution * @return a {@link Mono} with the result */ Mono intercept(WebInput webInput, WebGraphQLHandler next); @@ -61,7 +61,7 @@ public interface WebInterceptor { /** * Return {@link WebGraphQLHandler} that invokes the current interceptor * first and then the given {@link GraphQLService} for actual execution of - * the GraphQL query. + * the GraphQL operation. */ default WebGraphQLHandler apply(GraphQLService service) { Assert.notNull(service, "GraphQLService must not be null"); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/WebOutput.java b/spring-graphql/src/main/java/org/springframework/graphql/web/WebOutput.java index 108343cc..c428681a 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/WebOutput.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/WebOutput.java @@ -173,7 +173,7 @@ public class WebOutput implements ExecutionResult { /** * Add a custom header to be set on the HTTP response. * - *

Note: This can be used for GraphQL over HTTP query + *

Note: This can be used for GraphQL over HTTP * requests but has no impact for queries over a WebSocket session where * the initial handshake request completes before queries begin. */ @@ -188,7 +188,7 @@ public class WebOutput implements ExecutionResult { /** * Consume and update the headers to be set on the HTTP response. * - *

Note: This can be used for GraphQL over HTTP query + *

Note: This can be used for GraphQL over HTTP * requests but has no impact for queries over a WebSocket session where * the initial handshake request completes before queries begin. */ diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQLHttpHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQLHttpHandler.java index 1144097a..64a6ec4e 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQLHttpHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQLHttpHandler.java @@ -53,9 +53,9 @@ public class GraphQLHttpHandler { /** - * Handle GraphQL query requests over HTTP. + * Handle GraphQL requests over HTTP. */ - public Mono handleQuery(ServerRequest request) { + public Mono handleRequest(ServerRequest request) { return request.bodyToMono(MAP_PARAMETERIZED_TYPE_REF) .flatMap(body -> { String id = request.exchange().getRequest().getId(); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQLWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQLWebSocketHandler.java index 4fa7aa7b..292be31d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQLWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQLWebSocketHandler.java @@ -221,7 +221,7 @@ public class GraphQLWebSocketHandler implements WebSocketHandler { }); } else { - // Query + // Single response operation (query or mutation) outputFlux = (CollectionUtils.isEmpty(output.getErrors()) ? Flux.just(output) : Flux.error(new IllegalStateException("Execution failed: " + output.getErrors()))); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQLHttpHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQLHttpHandler.java index 3daa1830..b8f06f8d 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQLHttpHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQLHttpHandler.java @@ -64,7 +64,7 @@ public class GraphQLHttpHandler { * @throws ServletException may be raised when reading the request body, * e.g. {@link HttpMediaTypeNotSupportedException}. */ - public ServerResponse handle(ServerRequest request) throws ServletException { + public ServerResponse handleRequest(ServerRequest request) throws ServletException { WebInput input = new WebInput(request.uri(), request.headers().asHttpHeaders(), readBody(request), null); if (logger.isDebugEnabled()) { logger.debug("Executing: " + input); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQLWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQLWebSocketHandler.java index f539f5f5..8601db03 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQLWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQLWebSocketHandler.java @@ -219,7 +219,7 @@ public class GraphQLWebSocketHandler extends TextWebSocketHandler implements Sub }); } else { - // Query + // Single response operation (query or mutation) outputFlux = (CollectionUtils.isEmpty(output.getErrors()) ? Flux.just(output) : Flux.error(new IllegalStateException("Execution failed: " + output.getErrors())));