use of org.springframework.graphql.web.WebInput in project spring-graphql by spring-projects.
the class GraphQlHttpHandler method handleRequest.
/**
* Handle GraphQL requests over HTTP.
* @param request the incoming HTTP request
* @return the HTTP response
*/
public Mono<ServerResponse> handleRequest(ServerRequest request) {
return request.bodyToMono(MAP_PARAMETERIZED_TYPE_REF).flatMap((body) -> {
WebInput input = new WebInput(request.uri(), request.headers().asHttpHeaders(), body, request.exchange().getRequest().getId(), request.exchange().getLocaleContext().getLocale());
if (logger.isDebugEnabled()) {
logger.debug("Executing: " + input);
}
return this.graphQlHandler.handleRequest(input);
}).flatMap((output) -> {
Map<String, Object> spec = output.toSpecification();
if (logger.isDebugEnabled()) {
logger.debug("Execution complete");
}
ServerResponse.BodyBuilder builder = ServerResponse.ok();
builder.headers(headers -> headers.putAll(output.getResponseHeaders()));
return builder.bodyValue(spec);
});
}
use of org.springframework.graphql.web.WebInput in project spring-graphql by spring-projects.
the class WebGraphQlClientBuilderTests method mutateUrlHeaders.
@ParameterizedTest
@MethodSource("argumentSource")
void mutateUrlHeaders(ClientBuilderSetup builderSetup) {
String url = "/graphql-one";
// Original
WebGraphQlClient.Builder<?> builder = builderSetup.initBuilder().url(url).headers(headers -> headers.add("h", "one"));
WebGraphQlClient client = builder.build();
client.document(DOCUMENT).execute().block(TIMEOUT);
WebInput input = builderSetup.getWebInput();
assertThat(input.getUri().toString()).isEqualTo(url);
assertThat(input.getHeaders().get("h")).containsExactly("one");
// Mutate to add header value
builder = client.mutate().headers(headers -> headers.add("h", "two"));
client = builder.build();
client.document(DOCUMENT).execute().block(TIMEOUT);
assertThat(builderSetup.getWebInput().getHeaders().get("h")).containsExactly("one", "two");
// Mutate to replace header
builder = client.mutate().header("h", "three", "four");
client = builder.build();
client.document(DOCUMENT).execute().block(TIMEOUT);
input = builderSetup.getWebInput();
assertThat(input.getUri().toString()).isEqualTo(url);
assertThat(input.getHeaders().get("h")).containsExactly("three", "four");
}
use of org.springframework.graphql.web.WebInput in project spring-graphql by spring-projects.
the class WebGraphQlTesterBuilderTests method mutateUrlHeaders.
@ParameterizedTest
@MethodSource("argumentSource")
void mutateUrlHeaders(TesterBuilderSetup builderSetup) {
String url = "/graphql-one";
// Original
WebGraphQlTester.Builder<?> builder = builderSetup.initBuilder().url(url).headers(headers -> headers.add("h", "one"));
WebGraphQlTester tester = builder.build();
tester.document(DOCUMENT).execute();
WebInput input = builderSetup.getWebInput();
assertThat(input.getUri().toString()).isEqualTo(url);
assertThat(input.getHeaders().get("h")).containsExactly("one");
// Mutate to add header value
builder = tester.mutate().headers(headers -> headers.add("h", "two"));
tester = builder.build();
tester.document(DOCUMENT).execute();
assertThat(builderSetup.getWebInput().getHeaders().get("h")).containsExactly("one", "two");
// Mutate to replace header
builder = tester.mutate().header("h", "three", "four");
tester = builder.build();
tester.document(DOCUMENT).execute();
input = builderSetup.getWebInput();
assertThat(input.getUri().toString()).isEqualTo(url);
assertThat(input.getHeaders().get("h")).containsExactly("three", "four");
}
Aggregations