jdaugherty commented on code in PR #15677:
URL: https://github.com/apache/grails-core/pull/15677#discussion_r3343543198


##########
grails-data-graphql/plugin/src/main/groovy/org/grails/gorm/graphql/plugin/testing/GraphQLSpec.groovy:
##########
@@ -56,59 +65,90 @@ trait GraphQLSpec {
     @TupleConstructor
     static class GraphQLRequestHelper {
 
-        RxHttpClient rest
+        private static final MediaType APPLICATION_GRAPHQL = 
MediaType.parseMediaType('application/graphql')
+        private static final JsonSlurper SLURPER = new JsonSlurper()
 
-        HttpResponse<Map> graphql(String requestBody) {
-            rest.exchange(HttpRequest.POST('/graphql', 
requestBody).contentType('application/graphql'), Map)
-                    .firstOrError().blockingGet()
+        RestClient rest
+
+        ResponseEntity<Map> graphql(String requestBody) {
+            wrapJson(exchangeGraphql(requestBody))
+        }
+
+        // Overload that returns the raw body for callers asserting on the
+        // unparsed JSON payload (only String is supported - tests asserting on
+        // a structured body should use the no-class overload above which 
parses
+        // into a Map).
+        @SuppressWarnings('unchecked')
+        def <T> ResponseEntity<T> graphql(String requestBody, Class<T> 
bodyType) {
+            if (bodyType != String) {
+                throw new IllegalArgumentException(
+                        "graphql(String, Class) only supports String.class; 
got ${bodyType.name}")
+            }
+            (ResponseEntity<T>) exchangeGraphql(requestBody)
         }
 
-        def <T> HttpResponse<T> graphql(String requestBody, Class<T> bodyType) 
{
-            rest.exchange(HttpRequest.POST('/graphql', 
requestBody).contentType('application/graphql'), bodyType)
-                    .firstOrError().blockingGet()
+        private ResponseEntity<String> exchangeGraphql(String requestBody) {
+            rest.post()
+                    .uri('/graphql')
+                    .contentType(APPLICATION_GRAPHQL)
+                    .body(requestBody)
+                    .retrieve()
+                    .toEntity(String)
         }
 
-        private HttpResponse<Map> buildJsonRequest(Map<String, Object> data) {
-            rest.exchange(HttpRequest.POST('/graphql', data), 
Map).firstOrError().blockingGet()
+        private ResponseEntity<Map> buildJsonRequest(Map<String, Object> data) 
{
+            wrapJson(rest.post()
+                    .uri('/graphql')
+                    .contentType(MediaType.APPLICATION_JSON)
+                    .body(JsonOutput.toJson(data))

Review Comment:
   Why are you reimplementing json encoding and not using spring's built in 
mechanism? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to