Skip to content

Commit 7acbffe

Browse files
committed
Fix invalid syntax for JDK8
1 parent 12e7d75 commit 7acbffe

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

spring-graphql/src/main/java/org/springframework/graphql/server/WebGraphQlRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public WebGraphQlRequest(
6969

7070
private static String getQuery(Map<String, Object> body) {
7171
Object value = body.get("query");
72-
if (!(value instanceof String query) || !StringUtils.hasText(query)) {
72+
if (!(value instanceof String) || !StringUtils.hasText((String) value)) {
7373
throw new ServerWebInputException("Invalid value for 'query'");
7474
}
7575
return (String) value;

spring-graphql/src/test/java/org/springframework/graphql/server/WebGraphQlRequestTests.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.net.URI;
2020
import java.util.Collections;
21+
import java.util.HashMap;
2122
import java.util.Map;
2223

2324
import org.junit.jupiter.api.Test;
@@ -37,18 +38,28 @@ public class WebGraphQlRequestTests {
3738

3839
@Test // gh-726
3940
void invalidBody() {
40-
testInvalidBody(Map.of());
41-
testInvalidBody(Map.of("query", Collections.emptyMap()));
42-
testInvalidBody(Map.of("query", "query { foo }", "operation", Collections.emptyMap()));
43-
testInvalidBody(Map.of("query", "query { foo }", "variables", "not-a-map"));
44-
testInvalidBody(Map.of("query", "query { foo }", "extensions", "not-a-map"));
41+
testInvalidBody(new HashMap<>());
42+
Map<String, Object> empty = new HashMap<>();
43+
empty.put("query", Collections.emptyMap());
44+
testInvalidBody(empty);
45+
Map<String, Object> emptyOperations = new HashMap<>();
46+
emptyOperations.put("query", "query { foo }");
47+
emptyOperations.put("operation", Collections.emptyMap());
48+
testInvalidBody(emptyOperations);
49+
Map<String, Object> invalidVariables = new HashMap<>();
50+
invalidVariables.put("query", "query { foo }");
51+
invalidVariables.put("variables", "not-a-map");
52+
testInvalidBody(invalidVariables);
53+
Map<String, Object> invalidExtensions = new HashMap<>();
54+
invalidExtensions.put("query", "query { foo }");
55+
invalidExtensions.put("extensions", "not-a-map");
56+
testInvalidBody(invalidExtensions);
4557
}
4658

4759
private void testInvalidBody(Map<String, Object> body) {
4860
assertThatThrownBy(() ->
4961
new WebGraphQlRequest(
50-
URI.create("/graphql"), new HttpHeaders(), new LinkedMultiValueMap<>(),
51-
Collections.emptyMap(), body, "1", null))
62+
URI.create("/graphql"), new HttpHeaders(), body, "1", null))
5263
.isInstanceOf(ServerWebInputException.class);
5364
}
5465

0 commit comments

Comments
 (0)