GraphQlTester provides access to underlying response
Closes gh-1131
This commit is contained in:
@@ -309,12 +309,15 @@ final class DefaultGraphQlTester implements GraphQlTester {
|
||||
*/
|
||||
private static final class DefaultResponse implements Response, Errors {
|
||||
|
||||
private final GraphQlResponse response;
|
||||
|
||||
private final ResponseDelegate delegate;
|
||||
|
||||
private DefaultResponse(
|
||||
GraphQlResponse response, @Nullable Predicate<ResponseError> errorFilter,
|
||||
Consumer<Runnable> assertDecorator, Configuration jsonPathConfig) {
|
||||
|
||||
this.response = response;
|
||||
this.delegate = new ResponseDelegate(response, errorFilter, assertDecorator, jsonPathConfig);
|
||||
}
|
||||
|
||||
@@ -335,6 +338,11 @@ final class DefaultGraphQlTester implements GraphQlTester {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphQlResponse returnResponse() {
|
||||
return this.response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Errors filter(Predicate<ResponseError> predicate) {
|
||||
this.delegate.filterErrors(predicate);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import java.util.function.Predicate;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.GraphQlResponse;
|
||||
import org.springframework.graphql.ResponseError;
|
||||
import org.springframework.graphql.client.GraphQlTransport;
|
||||
import org.springframework.graphql.support.DocumentSource;
|
||||
@@ -262,6 +263,13 @@ public interface GraphQlTester {
|
||||
*/
|
||||
Errors errors();
|
||||
|
||||
|
||||
/**
|
||||
* Return the underlying {@link GraphQlResponse} for direct access.
|
||||
* @since 1.3.5
|
||||
*/
|
||||
GraphQlResponse returnResponse();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,6 +30,7 @@ import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.ExecutionGraphQlRequest;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.GraphQlRequest;
|
||||
import org.springframework.graphql.GraphQlResponse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
@@ -500,4 +501,14 @@ public class GraphQlTesterTests extends GraphQlTesterTestSupport {
|
||||
assertThat(getActualRequestDocument()).contains(document);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnGraphQlResponse() {
|
||||
String document = "{me {name, friends}}";
|
||||
getGraphQlService().setDataAsJson(document, "{\"me\": {\"name\":\"Luke Skywalker\", \"friends\":[]}}");
|
||||
|
||||
GraphQlResponse response = graphQlTester().documentName("me").execute().returnResponse();
|
||||
String value = response.field("me.name").getValue();
|
||||
assertThat(value).isEqualTo("Luke Skywalker");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user