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

Commit 92c28bf

Browse files
authored
Merge pull request #666 from ObeyYourMaster/fix/apq-not-working
fix: 'Invalid Syntax : offending token '<EOF>'' when using Apollo persisted queries
2 parents 4d5fb1f + 3003f52 commit 92c28bf

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

graphql-kickstart-spring-support/src/main/java/graphql/kickstart/spring/AbstractGraphQLController.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public Object graphqlPOST(
3939
@Nullable @RequestParam(value = "query", required = false) String query,
4040
@Nullable @RequestParam(value = "operationName", required = false) String operationName,
4141
@Nullable @RequestParam(value = "variables", required = false) String variablesJson,
42+
@Nullable @RequestParam(value = "extensions", required = false) String extensionsJson,
4243
@Nullable @RequestBody(required = false) String body,
4344
ServerWebExchange serverWebExchange) {
4445

@@ -58,6 +59,7 @@ public Object graphqlPOST(
5859
request.getQuery(),
5960
request.getOperationName(),
6061
request.getVariables(),
62+
request.getExtensions(),
6163
serverWebExchange);
6264
}
6365

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

6971
if (query != null) {
7072
return executeRequest(
71-
query, operationName, convertVariablesJson(variablesJson), serverWebExchange);
73+
query,
74+
operationName,
75+
convertVariablesJson(variablesJson),
76+
convertExtensionsJson(extensionsJson),
77+
serverWebExchange);
7278
}
7379

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

7783
if ("application/graphql".equals(contentType.toString())
7884
|| "application/graphql; charset=utf-8".equals(contentType.toString())) {
79-
return executeRequest(body, null, Collections.emptyMap(), serverWebExchange);
85+
return executeRequest(
86+
body, null, Collections.emptyMap(), Collections.emptyMap(), serverWebExchange);
8087
}
8188

8289
throw new ResponseStatusException(
@@ -88,10 +95,14 @@ public Object graphqlGET(
8895
@Nullable @RequestParam("query") String query,
8996
@Nullable @RequestParam(value = "operationName", required = false) String operationName,
9097
@Nullable @RequestParam(value = "variables", required = false) String variablesJson,
98+
@Nullable @RequestParam(value = "extensions", required = false) String extensionsJson,
9199
ServerWebExchange serverWebExchange) {
92-
93100
return executeRequest(
94-
query, operationName, convertVariablesJson(variablesJson), serverWebExchange);
101+
query == null ? "" : query,
102+
operationName,
103+
convertVariablesJson(variablesJson),
104+
convertExtensionsJson(extensionsJson),
105+
serverWebExchange);
95106
}
96107

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

114+
private Map<String, Object> convertExtensionsJson(String jsonMap) {
115+
return Optional.ofNullable(jsonMap)
116+
.map(objectMapper::deserializeExtensions)
117+
.orElseGet(Collections::emptyMap);
118+
}
119+
103120
protected abstract Object executeRequest(
104121
String query,
105122
String operationName,
106123
Map<String, Object> variables,
124+
Map<String, Object> extensions,
107125
ServerWebExchange serverWebExchange);
108126

109127
protected Object handleBodyParsingException(Exception exception) {

graphql-kickstart-spring-webflux/src/main/java/graphql/kickstart/spring/webflux/GraphQLController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ protected Object executeRequest(
3333
String query,
3434
String operationName,
3535
Map<String, Object> variables,
36+
Map<String, Object> extensions,
3637
ServerWebExchange serverWebExchange) {
3738
GraphQLSingleInvocationInput invocationInput =
3839
invocationInputFactory.create(
39-
new GraphQLRequest(query, variables, operationName), serverWebExchange);
40+
new GraphQLRequest(query, variables, extensions, operationName), serverWebExchange);
4041
Mono<ExecutionResult> executionResult =
4142
Mono.fromCompletionStage(graphQLInvoker.executeAsync(invocationInput));
4243
return executionResult.map(objectMapper::createResultFromExecutionResult);

0 commit comments

Comments
 (0)