Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into renovate/major-graphql-java-(ignoring-snap…
Browse files Browse the repository at this point in the history
…shot-builds)
  • Loading branch information
oliemansm committed Aug 19, 2021
2 parents ca87b82 + 92c28bf commit 47dfd95
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public Object graphqlPOST(
@Nullable @RequestParam(value = "query", required = false) String query,
@Nullable @RequestParam(value = "operationName", required = false) String operationName,
@Nullable @RequestParam(value = "variables", required = false) String variablesJson,
@Nullable @RequestParam(value = "extensions", required = false) String extensionsJson,
@Nullable @RequestBody(required = false) String body,
ServerWebExchange serverWebExchange) {

Expand All @@ -58,6 +59,7 @@ public Object graphqlPOST(
request.getQuery(),
request.getOperationName(),
request.getVariables(),
request.getExtensions(),
serverWebExchange);
}

Expand All @@ -68,15 +70,20 @@ public Object graphqlPOST(

if (query != null) {
return executeRequest(
query, operationName, convertVariablesJson(variablesJson), serverWebExchange);
query,
operationName,
convertVariablesJson(variablesJson),
convertExtensionsJson(extensionsJson),
serverWebExchange);
}

// * If the "application/graphql" Content-Type header is present,
// treat the HTTP POST body contents as the GraphQL query string.

if ("application/graphql".equals(contentType.toString())
|| "application/graphql; charset=utf-8".equals(contentType.toString())) {
return executeRequest(body, null, Collections.emptyMap(), serverWebExchange);
return executeRequest(
body, null, Collections.emptyMap(), Collections.emptyMap(), serverWebExchange);
}

throw new ResponseStatusException(
Expand All @@ -88,10 +95,14 @@ public Object graphqlGET(
@Nullable @RequestParam("query") String query,
@Nullable @RequestParam(value = "operationName", required = false) String operationName,
@Nullable @RequestParam(value = "variables", required = false) String variablesJson,
@Nullable @RequestParam(value = "extensions", required = false) String extensionsJson,
ServerWebExchange serverWebExchange) {

return executeRequest(
query, operationName, convertVariablesJson(variablesJson), serverWebExchange);
query == null ? "" : query,
operationName,
convertVariablesJson(variablesJson),
convertExtensionsJson(extensionsJson),
serverWebExchange);
}

private Map<String, Object> convertVariablesJson(String jsonMap) {
Expand All @@ -100,10 +111,17 @@ private Map<String, Object> convertVariablesJson(String jsonMap) {
.orElseGet(Collections::emptyMap);
}

private Map<String, Object> convertExtensionsJson(String jsonMap) {
return Optional.ofNullable(jsonMap)
.map(objectMapper::deserializeExtensions)
.orElseGet(Collections::emptyMap);
}

protected abstract Object executeRequest(
String query,
String operationName,
Map<String, Object> variables,
Map<String, Object> extensions,
ServerWebExchange serverWebExchange);

protected Object handleBodyParsingException(Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ protected Object executeRequest(
String query,
String operationName,
Map<String, Object> variables,
Map<String, Object> extensions,
ServerWebExchange serverWebExchange) {
GraphQLSingleInvocationInput invocationInput =
invocationInputFactory.create(
new GraphQLRequest(query, variables, null, operationName), serverWebExchange);
new GraphQLRequest(query, variables, extensions, operationName), serverWebExchange);
Mono<ExecutionResult> executionResult =
Mono.fromCompletionStage(graphQLInvoker.executeAsync(invocationInput));
return executionResult.map(objectMapper::createResultFromExecutionResult);
Expand Down

0 comments on commit 47dfd95

Please sign in to comment.