Skip to content

Commit

Permalink
Refine use of "query" in type and method names
Browse files Browse the repository at this point in the history
Following revisions in the spec
graphql/graphql-spec#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.
  • Loading branch information
rstoyanchev committed May 12, 2021
1 parent f70e552 commit 44a034e
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class GraphQLProperties {

/**
* Path of the GraphQL HTTP query endpoint.
* Path at which to expose a GraphQL request HTTP endpoint.
*/
private String path = "/graphql";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public RouterFunction<ServerResponse> graphQLEndpoint(GraphQLHttpHandler handler
}
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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public GraphQLHttpHandler graphQLHttpHandler(WebGraphQLHandler webGraphQLHandler
}

@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();
Expand All @@ -93,7 +93,7 @@ public RouterFunction<ServerResponse> graphQLQueryEndpoint(GraphQLHttpHandler ha
}
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(),
Expand Down Expand Up @@ -122,7 +122,7 @@ public GraphQLWebSocketHandler graphQLWebSocketHandler(
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ private Configuration initJsonPathConfig() {


@Override
public QuerySpec query(String query) {
return new DefaultQuerySpec(query);
public RequestSpec query(String query) {
return new DefaultRequestSpec(query);
}


Expand All @@ -105,7 +105,7 @@ public QuerySpec query(String query) {
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);

Expand Down Expand Up @@ -153,11 +153,11 @@ public ResponseSpec execute(RequestInput requestInput) {
}

@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)
Expand Down Expand Up @@ -224,17 +224,17 @@ private Consumer<Runnable> assertDecorator(RequestInput input) {
assertion.run();
}
catch (AssertionError ex) {
throw new AssertionError(ex.getMessage() + "\nQuery: " + input, ex);
throw new AssertionError(ex.getMessage() + "\nRequest: " + input, ex);
}
};
}
}


/**
* {@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;

Expand All @@ -243,25 +243,25 @@ private class DefaultQuerySpec implements QuerySpec {

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@
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);


/**
Expand Down Expand Up @@ -157,24 +158,24 @@ interface ExecuteSpec {


/**
* 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);
}


Expand All @@ -185,8 +186,8 @@ interface TraverseSpec {

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getQuery() {
}

/**
* 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
Expand All @@ -78,7 +78,7 @@ public String getOperationName() {
}

/**
* 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() {
Expand All @@ -98,7 +98,7 @@ public void configureExecutionInput(BiFunction<ExecutionInput, ExecutionInput.Bu
}

/**
* 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)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static Map<String, Object> validateQuery(Map<String, Object> body) {

/**
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* 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()}.
Expand All @@ -39,12 +39,12 @@
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);
Expand All @@ -61,7 +61,7 @@ default WebInterceptor andThen(WebInterceptor interceptor) {
/**
* 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public Builder extensions(@Nullable Map<Object, Object> extensions) {
/**
* 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.
*/
Expand All @@ -188,7 +188,7 @@ public Builder responseHeader(String name, String... values) {
/**
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public GraphQLHttpHandler(WebGraphQLHandler graphQLHandler) {


/**
* 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private Flux<WebSocketMessage> handleWebOutput(
});
}
else {
// Query
// Single response operation (query or mutation)
outputFlux = (CollectionUtils.isEmpty(output.getErrors()) ?
Flux.just(output) :
Flux.error(new IllegalStateException("Execution failed: " + output.getErrors())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public GraphQLHttpHandler(WebGraphQLHandler graphQLHandler) {
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private Flux<TextMessage> handleWebOutput(WebSocketSession session, String id, W
});
}
else {
// Query
// Single response operation (query or mutation)
outputFlux = (CollectionUtils.isEmpty(output.getErrors()) ?
Flux.just(output) :
Flux.error(new IllegalStateException("Execution failed: " + output.getErrors())));
Expand Down

0 comments on commit 44a034e

Please sign in to comment.