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


##########
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)

Review Comment:
   You were right that it didn't work. I added a mock-HTTP-server (Ersatz) 
spec, GraphQLSpecSpec, covering the application/graphql POST, the JSON POST 
(asserting the Jackson-encoded request body), the GET helper, and Map response 
parsing. Writing it surfaced two real bugs: RestClient had no JSON converter 
because the example apps don't pull Jackson onto the classpath (now declared 
integrationTestRuntimeOnly), and the GET helper targeted the app root and 
expanded the GraphQL query braces as URI templates (now targets /graphql with 
values bound as URI variables). All four graphql integration suites plus the 
new spec pass on JDK 21. Fixed in c54d35e.



##########
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

Review Comment:
   Agreed. The trait now lets RestClient encode and decode JSON through its 
Jackson message converter, so the encoding is driven by the message converter 
as you said. I corrected the guide note accordingly - the previous 'serializes 
using JsonOutput/JsonSlurper' wording is gone. Fixed in c54d35e.



-- 
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