use of org.springframework.graphql.execution.DataFetcherExceptionResolver in project spring-graphql by spring-projects.
the class WebGraphQlHandlerTests method reactorContextPropagationToExceptionResolver.
@Test
void reactorContextPropagationToExceptionResolver() {
DataFetcherExceptionResolver exceptionResolver = (ex, env) -> Mono.deferContextual((view) -> Mono.just(Collections.singletonList(GraphqlErrorBuilder.newError(env).message("Resolved error: " + ex.getMessage() + ", name=" + view.get("name")).errorType(ErrorType.BAD_REQUEST).build())));
Mono<WebOutput> outputMono = this.graphQlSetup.queryFetcher("greeting", this.errorDataFetcher).exceptionResolver(exceptionResolver).toWebGraphQlHandler().handleRequest(webInput).contextWrite((cxt) -> cxt.put("name", "007"));
GraphQlResponse response = GraphQlResponse.from(outputMono);
assertThat(response.errorCount()).isEqualTo(1);
assertThat(response.error(0).message()).isEqualTo("Resolved error: Invalid greeting, name=007");
String greeting = response.rawValue("greeting");
assertThat(greeting).isNull();
}
Aggregations