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.
This commit is contained in:
@@ -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";
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -83,7 +83,7 @@ public class WebMvcGraphQLAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RouterFunction<ServerResponse> graphQLQueryEndpoint(GraphQLHttpHandler handler, GraphQLSource graphQLSource,
|
||||
public RouterFunction<ServerResponse> 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);
|
||||
|
||||
@@ -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<TestExecutionResult> 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<String, Object> 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<Map<String, Object>> variablesConsumer) {
|
||||
public RequestSpec variables(Consumer<Map<String, Object>> variablesConsumer) {
|
||||
variablesConsumer.accept(this.variables);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -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<Map<String, Object>> variablesConsumer);
|
||||
RequestSpec variables(Consumer<Map<String, Object>> 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
|
||||
* <a href="https://github.com/jayway/JsonPath">JsonPath</a>.
|
||||
*
|
||||
* @param path the path to switch to
|
||||
|
||||
@@ -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<ExecutionResult> execute(ExecutionInput input);
|
||||
|
||||
@@ -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<String, Object> 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)}.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<WebOutput> handle(WebInput input);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>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<WebOutput> 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");
|
||||
|
||||
@@ -173,7 +173,7 @@ public class WebOutput implements ExecutionResult {
|
||||
/**
|
||||
* Add a custom header to be set on the HTTP response.
|
||||
*
|
||||
* <p><strong>Note:</strong> This can be used for GraphQL over HTTP query
|
||||
* <p><strong>Note:</strong> 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.
|
||||
*
|
||||
* <p><strong>Note:</strong> This can be used for GraphQL over HTTP query
|
||||
* <p><strong>Note:</strong> 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.
|
||||
*/
|
||||
|
||||
@@ -53,9 +53,9 @@ public class GraphQLHttpHandler {
|
||||
|
||||
|
||||
/**
|
||||
* Handle GraphQL query requests over HTTP.
|
||||
* Handle GraphQL requests over HTTP.
|
||||
*/
|
||||
public Mono<ServerResponse> handleQuery(ServerRequest request) {
|
||||
public Mono<ServerResponse> handleRequest(ServerRequest request) {
|
||||
return request.bodyToMono(MAP_PARAMETERIZED_TYPE_REF)
|
||||
.flatMap(body -> {
|
||||
String id = request.exchange().getRequest().getId();
|
||||
|
||||
@@ -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())));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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())));
|
||||
|
||||
Reference in New Issue
Block a user