Correctly retrieve operation from request body

See gh-742
This commit is contained in:
Koen Punt
2023-06-27 15:13:27 +02:00
committed by rstoyanchev
parent 6068e64b37
commit e742404841
2 changed files with 3 additions and 3 deletions

View File

@@ -105,9 +105,9 @@ public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements
@Nullable
private static String getOperation(Map<String, Object> body) {
Object value = body.get("operation");
Object value = body.get("operationName");
if (value != null && !(value instanceof String)) {
throw new ServerWebInputException("Invalid value for 'operation'");
throw new ServerWebInputException("Invalid value for 'operationName'");
}
return (String) value;
}

View File

@@ -39,7 +39,7 @@ public class WebGraphQlRequestTests {
void invalidBody() {
testInvalidBody(Map.of());
testInvalidBody(Map.of("query", Collections.emptyMap()));
testInvalidBody(Map.of("query", "query { foo }", "operation", Collections.emptyMap()));
testInvalidBody(Map.of("query", "query { foo }", "operationName", Collections.emptyMap()));
testInvalidBody(Map.of("query", "query { foo }", "variables", "not-a-map"));
testInvalidBody(Map.of("query", "query { foo }", "extensions", "not-a-map"));
}