jamesfredley commented on code in PR #15677:
URL: https://github.com/apache/grails-core/pull/15677#discussion_r3351587043
##########
grails-data-graphql/plugin/src/main/groovy/org/grails/gorm/graphql/plugin/testing/GraphQLSpec.groovy:
##########
@@ -37,7 +38,15 @@ trait GraphQLSpec {
GraphQLRequestHelper getGraphQL() {
if (_graphql == null) {
- _graphql = new GraphQLRequestHelper(rest: RxHttpClient.create(new
URL(getServerUrl())))
+ StringHttpMessageConverter stringConverter = new
StringHttpMessageConverter()
+ stringConverter.supportedMediaTypes = [MediaType.ALL]
+ _graphql = new GraphQLRequestHelper(rest: RestClient.builder()
+ .baseUrl(getServerUrl())
+ .messageConverters({ converters ->
+ converters.clear()
Review Comment:
Removed the converters.clear() / StringHttpMessageConverter workaround. The
helper now uses RestClient's default message converters, so there is no cached
or custom converter state - the Jackson converter handles JSON. 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
+
+ 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:
Done. The JSON request body is now passed as a Map and serialized by
RestClient's Jackson message converter, and the response is read back with
toEntity(Map). JsonOutput/JsonSlurper are gone from the POST paths. 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]