Simplify request execution in tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -31,7 +31,6 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.ExecutionGraphQlResponse;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.TestExecutionRequest;
|
||||
import org.springframework.graphql.data.method.annotation.BatchMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@@ -72,8 +71,7 @@ public class BatchMappingInvocationTests extends BatchMappingTestSupport {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = createGraphQlService(controller)
|
||||
.execute(TestExecutionRequest.forDocument(query));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = createGraphQlService(controller).execute(query);
|
||||
|
||||
List<Course> actualCourses = ResponseHelper.forResponse(responseMono).toList("courses", Course.class);
|
||||
List<Course> courses = Course.allCourses();
|
||||
@@ -105,8 +103,7 @@ public class BatchMappingInvocationTests extends BatchMappingTestSupport {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = createGraphQlService(controller)
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = createGraphQlService(controller).execute(document);
|
||||
|
||||
List<Course> actualCourses = ResponseHelper.forResponse(responseMono).toList("courses", Course.class);
|
||||
List<Course> courses = Course.allCourses();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -94,7 +94,7 @@ public class BatchMappingPrincipalMethodArgumentResolverTests extends BatchMappi
|
||||
Mono<ExecutionGraphQlResponse> responseMono = Mono.delay(Duration.ofMillis(10))
|
||||
.flatMap(aLong -> {
|
||||
String document = "{ courses { id instructor { id } } }";
|
||||
return createGraphQlService(controller).execute(TestExecutionRequest.forDocument(document));
|
||||
return createGraphQlService(controller).execute(document);
|
||||
})
|
||||
.contextWrite(contextWriter);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -29,8 +29,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.GraphQlSetup;
|
||||
import org.springframework.graphql.TestExecutionGraphQlService;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.execution.BatchLoaderRegistry;
|
||||
import org.springframework.graphql.execution.DefaultBatchLoaderRegistry;
|
||||
@@ -80,7 +80,7 @@ public class BatchMappingTestSupport {
|
||||
"}";
|
||||
|
||||
|
||||
protected ExecutionGraphQlService createGraphQlService(CourseController controller) {
|
||||
protected TestExecutionGraphQlService createGraphQlService(CourseController controller) {
|
||||
BatchLoaderRegistry registry = new DefaultBatchLoaderRegistry();
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@@ -40,9 +40,9 @@ import org.springframework.graphql.BookCriteria;
|
||||
import org.springframework.graphql.BookSource;
|
||||
import org.springframework.graphql.ExecutionGraphQlRequest;
|
||||
import org.springframework.graphql.ExecutionGraphQlResponse;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.GraphQlSetup;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.TestExecutionGraphQlService;
|
||||
import org.springframework.graphql.TestExecutionRequest;
|
||||
import org.springframework.graphql.data.method.annotation.Argument;
|
||||
import org.springframework.graphql.data.method.annotation.GraphQlExceptionHandler;
|
||||
@@ -80,7 +80,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
|
||||
|
||||
Book book = ResponseHelper.forResponse(responseMono).toEntity("bookById", Book.class);
|
||||
assertThat(book.getId()).isEqualTo(1);
|
||||
@@ -100,7 +100,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
|
||||
|
||||
List<Book> bookList = ResponseHelper.forResponse(responseMono).toList("booksByCriteria", Book.class);
|
||||
assertThat(bookList).hasSize(2);
|
||||
@@ -117,7 +117,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
|
||||
|
||||
List<Book> bookList = ResponseHelper.forResponse(responseMono).toList("booksByProjectedArguments", Book.class);
|
||||
assertThat(bookList).hasSize(2);
|
||||
@@ -134,7 +134,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
|
||||
|
||||
List<Book> bookList = ResponseHelper.forResponse(responseMono).toList("booksByProjectedCriteria", Book.class);
|
||||
assertThat(bookList).hasSize(2);
|
||||
@@ -179,7 +179,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
|
||||
|
||||
Author author = ResponseHelper.forResponse(responseMono).toEntity("addAuthor", Author.class);
|
||||
assertThat(author.getId()).isEqualTo(99);
|
||||
@@ -196,7 +196,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
|
||||
|
||||
Flux<Book> bookFlux = ResponseHelper.forSubscription(responseMono)
|
||||
.map(response -> response.toEntity("bookSearch", Book.class));
|
||||
@@ -222,8 +222,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono =
|
||||
graphQlService().execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
|
||||
|
||||
ResponseHelper responseHelper = ResponseHelper.forResponse(responseMono);
|
||||
assertThat(responseHelper.errorCount()).isEqualTo(1);
|
||||
@@ -246,12 +245,12 @@ public class SchemaMappingInvocationTests {
|
||||
.message("Rejected: " + ex.getMessage())
|
||||
.build()));
|
||||
|
||||
ExecutionGraphQlService service = graphQlService((configurer, setup) -> {
|
||||
TestExecutionGraphQlService service = graphQlService((configurer, setup) -> {
|
||||
setup.exceptionResolver(configurer.getExceptionResolver()); // First @ControllerAdvice (no match)
|
||||
setup.exceptionResolver(resolver); // Then resolver
|
||||
});
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = service.execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = service.execute(document);
|
||||
|
||||
ResponseHelper responseHelper = ResponseHelper.forResponse(responseMono);
|
||||
assertThat(responseHelper.errorCount()).isEqualTo(1);
|
||||
@@ -268,8 +267,7 @@ public class SchemaMappingInvocationTests {
|
||||
" }" +
|
||||
"}";
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono =
|
||||
graphQlService().execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlService().execute(document);
|
||||
|
||||
Flux<Book> bookFlux = ResponseHelper.forSubscription(responseMono)
|
||||
.map(response -> response.toEntity("bookSearch", Book.class));
|
||||
@@ -286,11 +284,11 @@ public class SchemaMappingInvocationTests {
|
||||
}
|
||||
|
||||
|
||||
private ExecutionGraphQlService graphQlService() {
|
||||
private TestExecutionGraphQlService graphQlService() {
|
||||
return graphQlService((configurer, setup) -> {});
|
||||
}
|
||||
|
||||
private ExecutionGraphQlService graphQlService(BiConsumer<AnnotatedControllerConfigurer, GraphQlSetup> consumer) {
|
||||
private TestExecutionGraphQlService graphQlService(BiConsumer<AnnotatedControllerConfigurer, GraphQlSetup> consumer) {
|
||||
BatchLoaderRegistry registry = new DefaultBatchLoaderRegistry();
|
||||
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
|
||||
@@ -27,10 +27,9 @@ import org.springframework.data.domain.Window;
|
||||
import org.springframework.graphql.Book;
|
||||
import org.springframework.graphql.BookSource;
|
||||
import org.springframework.graphql.ExecutionGraphQlResponse;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.GraphQlSetup;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.TestExecutionRequest;
|
||||
import org.springframework.graphql.TestExecutionGraphQlService;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.pagination.CursorStrategy;
|
||||
import org.springframework.graphql.data.query.ScrollPositionCursorStrategy;
|
||||
@@ -50,9 +49,8 @@ public class SchemaMappingPaginationTests {
|
||||
@Test
|
||||
void forwardPagination() {
|
||||
|
||||
String query = BookSource.booksConnectionQuery("first:2, after:\"O_3\"");
|
||||
|
||||
Mono<ExecutionGraphQlResponse> response = graphQlService().execute(TestExecutionRequest.forDocument(query));
|
||||
String document = BookSource.booksConnectionQuery("first:2, after:\"O_3\"");
|
||||
Mono<ExecutionGraphQlResponse> response = graphQlService().execute(document);
|
||||
|
||||
ResponseHelper.forResponse(response).assertData(
|
||||
"{\"books\":{" +
|
||||
@@ -68,7 +66,7 @@ public class SchemaMappingPaginationTests {
|
||||
"}}}");
|
||||
}
|
||||
|
||||
private ExecutionGraphQlService graphQlService() {
|
||||
private TestExecutionGraphQlService graphQlService() {
|
||||
|
||||
ScrollPositionCursorStrategy cursorStrategy = new ScrollPositionCursorStrategy();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -33,10 +33,9 @@ import reactor.util.context.Context;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.graphql.ExecutionGraphQlResponse;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.GraphQlSetup;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.TestExecutionRequest;
|
||||
import org.springframework.graphql.TestExecutionGraphQlService;
|
||||
import org.springframework.graphql.data.method.annotation.QueryMapping;
|
||||
import org.springframework.graphql.data.method.annotation.SubscriptionMapping;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -156,12 +155,12 @@ public class SchemaMappingPrincipalMethodArgumentResolverTests {
|
||||
context.registerBean(GreetingController.class, () -> greetingController);
|
||||
context.refresh();
|
||||
|
||||
ExecutionGraphQlService graphQlService = GraphQlSetup.schemaContent(schema)
|
||||
TestExecutionGraphQlService graphQlService = GraphQlSetup.schemaContent(schema)
|
||||
.runtimeWiringForAnnotatedControllers(context)
|
||||
.toGraphQlService();
|
||||
|
||||
return Mono.delay(Duration.ofMillis(10))
|
||||
.flatMap(aLong -> graphQlService.execute(TestExecutionRequest.forDocument(document)))
|
||||
.flatMap(aLong -> graphQlService.execute(document))
|
||||
.contextWrite(contextWriter);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ import org.springframework.graphql.BookSource;
|
||||
import org.springframework.graphql.ExecutionGraphQlResponse;
|
||||
import org.springframework.graphql.GraphQlSetup;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.TestExecutionRequest;
|
||||
import org.springframework.graphql.execution.ConnectionTypeDefinitionConfigurer;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ConnectionFieldTypeVisitor}.
|
||||
@@ -49,7 +47,7 @@ public class ConnectionFieldTypeVisitorTests {
|
||||
.dataFetcher("Query", "books", env -> BookSource.books())
|
||||
.connectionSupport(adapter)
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
|
||||
.execute(BookSource.booksConnectionQuery(null));
|
||||
|
||||
ResponseHelper.forResponse(response).assertData(
|
||||
"{\"books\":{" +
|
||||
@@ -78,7 +76,7 @@ public class ConnectionFieldTypeVisitorTests {
|
||||
.dataFetcher("Query", "books", new PropertyDataFetcher<>("books"))
|
||||
.connectionSupport(new ListConnectionAdapter())
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
|
||||
.execute(BookSource.booksConnectionQuery(null));
|
||||
|
||||
ResponseHelper.forResponse(response).assertData("{\"books\":null}");
|
||||
}
|
||||
@@ -90,7 +88,7 @@ public class ConnectionFieldTypeVisitorTests {
|
||||
.dataFetcher("Query", "books", environment -> null)
|
||||
.connectionSupport(new ListConnectionAdapter())
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(BookSource.booksConnectionQuery(null)));
|
||||
.execute(BookSource.booksConnectionQuery(null));
|
||||
|
||||
ResponseHelper.forResponse(response).assertData(
|
||||
"{\"books\":{" +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -28,10 +28,10 @@ import org.springframework.graphql.Author;
|
||||
import org.springframework.graphql.Book;
|
||||
import org.springframework.graphql.BookSource;
|
||||
import org.springframework.graphql.ExecutionGraphQlResponse;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.ExecutionGraphQlService;
|
||||
import org.springframework.graphql.GraphQlSetup;
|
||||
import org.springframework.graphql.TestExecutionRequest;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.TestExecutionGraphQlService;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class BatchLoadingTests {
|
||||
this.registry.forTypePair(Long.class, Author.class)
|
||||
.registerBatchLoader((ids, env) -> Flux.fromIterable(ids).map(BookSource::getAuthor));
|
||||
|
||||
ExecutionGraphQlService service = GraphQlSetup.schemaResource(BookSource.schema)
|
||||
TestExecutionGraphQlService service = GraphQlSetup.schemaResource(BookSource.schema)
|
||||
.queryFetcher("booksByCriteria", env -> {
|
||||
Map<String, Object> criteria = env.getArgument("criteria");
|
||||
String authorName = (String) criteria.get("author");
|
||||
@@ -76,7 +76,7 @@ public class BatchLoadingTests {
|
||||
.dataLoaders(this.registry)
|
||||
.toGraphQlService();
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = service.execute(TestExecutionRequest.forDocument(document));
|
||||
Mono<ExecutionGraphQlResponse> responseMono = service.execute(document);
|
||||
|
||||
List<Book> books = ResponseHelper.forResponse(responseMono).toList("booksByCriteria", Book.class);
|
||||
assertThat(books).hasSize(2);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -23,9 +23,8 @@ import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.ExecutionGraphQlResponse;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.GraphQlSetup;
|
||||
import org.springframework.graphql.TestExecutionRequest;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -85,7 +84,7 @@ public class ClassNameTypeResolverTests {
|
||||
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlSetup.queryFetcher("animals", env -> animalList)
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
.execute(document);
|
||||
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
for (int i = 0; i < animalList.size(); i++) {
|
||||
@@ -128,7 +127,7 @@ public class ClassNameTypeResolverTests {
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlSetup.queryFetcher("sightings", env -> animalAndPlantList)
|
||||
.typeResolver(typeResolver)
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
.execute(document);
|
||||
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
for (int i = 0; i < animalAndPlantList.size(); i++) {
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.graphql.BookSource;
|
||||
import org.springframework.graphql.ExecutionGraphQlResponse;
|
||||
import org.springframework.graphql.GraphQlSetup;
|
||||
import org.springframework.graphql.ResponseHelper;
|
||||
import org.springframework.graphql.TestExecutionRequest;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ConnectionTypeDefinitionConfigurer}.
|
||||
@@ -57,7 +56,7 @@ public class ConnectionTypeDefinitionConfigurerTests {
|
||||
Mono<ExecutionGraphQlResponse> response = initGraphQlSetup()
|
||||
.dataFetcher("Query", "books", dataFetcher)
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
.execute(document);
|
||||
|
||||
ResponseHelper.forResponse(response).assertData(
|
||||
"{\"books\":{" +
|
||||
|
||||
@@ -66,7 +66,7 @@ class GraphQlObservationInstrumentationTests {
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlSetup
|
||||
.queryFetcher("bookById", dataFetcher)
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
.execute(document);
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
|
||||
String name = response.rawValue("bookById.name");
|
||||
@@ -101,7 +101,7 @@ class GraphQlObservationInstrumentationTests {
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlSetup
|
||||
.queryFetcher("bookById", env -> BookSource.getBookWithoutAuthor(1L))
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
.execute(document);
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
TestObservationRegistryAssert.assertThat(this.observationRegistry).hasObservationWithNameEqualTo("graphql.request")
|
||||
.that().hasLowCardinalityKeyValue("graphql.outcome", "REQUEST_ERROR")
|
||||
@@ -127,7 +127,7 @@ class GraphQlObservationInstrumentationTests {
|
||||
.queryFetcher("bookById", env -> BookSource.getBookWithoutAuthor(1L))
|
||||
.dataFetcher("Book", "author", env -> BookSource.getAuthor(101L))
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
.execute(document);
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
TestObservationRegistryAssert.assertThat(this.observationRegistry).hasObservationWithNameEqualTo("graphql.request")
|
||||
.that().hasLowCardinalityKeyValue("graphql.outcome", "SUCCESS")
|
||||
@@ -169,7 +169,7 @@ class GraphQlObservationInstrumentationTests {
|
||||
.queryFetcher("bookById", env ->
|
||||
CompletableFuture.failedStage(new IllegalStateException("book fetching failure")))
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
.execute(document);
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
assertThat(response.error(0).message()).isEqualTo("Resolved error: book fetching failure");
|
||||
|
||||
@@ -207,15 +207,15 @@ class GraphQlObservationInstrumentationTests {
|
||||
}
|
||||
}
|
||||
""";
|
||||
ExecutionGraphQlRequest graphQlRequest = TestExecutionRequest.forDocument(document);
|
||||
ExecutionGraphQlRequest request = TestExecutionRequest.forDocument(document);
|
||||
Observation incoming = Observation.start("incoming", ObservationRegistry.create());
|
||||
graphQlRequest.configureExecutionInput((input, builder) ->
|
||||
request.configureExecutionInput((input, builder) ->
|
||||
builder.graphQLContext(contextBuilder -> contextBuilder.of(ObservationThreadLocalAccessor.KEY, incoming)).build());
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlSetup
|
||||
.queryFetcher("bookById", env -> BookSource.getBookWithoutAuthor(1L))
|
||||
.toGraphQlService()
|
||||
.execute(graphQlRequest);
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
.execute(request);
|
||||
ResponseHelper.forResponse(responseMono);
|
||||
|
||||
TestObservationRegistryAssert.assertThat(this.observationRegistry).hasObservationWithNameEqualTo("graphql.request")
|
||||
.that().hasParentObservationEqualTo(incoming);
|
||||
@@ -235,8 +235,8 @@ class GraphQlObservationInstrumentationTests {
|
||||
Mono<ExecutionGraphQlResponse> responseMono = graphQlSetup
|
||||
.queryFetcher("bookById", dataFetcher)
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
.execute(document);
|
||||
ResponseHelper.forResponse(responseMono);
|
||||
|
||||
TestObservationRegistryAssert.assertThat(this.observationRegistry).hasObservationWithNameEqualTo("graphql.request")
|
||||
.that().hasLowCardinalityKeyValue("graphql.outcome", "SUCCESS")
|
||||
@@ -275,8 +275,8 @@ class GraphQlObservationInstrumentationTests {
|
||||
.queryFetcher("bookById", bookDataFetcher)
|
||||
.dataFetcher("Book", "author", authorDataFetcher)
|
||||
.toGraphQlService()
|
||||
.execute(TestExecutionRequest.forDocument(document));
|
||||
ResponseHelper response = ResponseHelper.forResponse(responseMono);
|
||||
.execute(document);
|
||||
ResponseHelper.forResponse(responseMono);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -29,6 +29,6 @@ public interface GraphQlServiceSetup extends WebGraphQlSetup {
|
||||
|
||||
GraphQlServiceSetup dataLoaders(DataLoaderRegistrar... registrars);
|
||||
|
||||
ExecutionGraphQlService toGraphQlService();
|
||||
TestExecutionGraphQlService toGraphQlService();
|
||||
|
||||
}
|
||||
|
||||
@@ -154,11 +154,11 @@ public class GraphQlSetup implements GraphQlServiceSetup {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExecutionGraphQlService toGraphQlService() {
|
||||
public TestExecutionGraphQlService toGraphQlService() {
|
||||
GraphQlSource source = graphQlSourceBuilder.build();
|
||||
DefaultExecutionGraphQlService service = new DefaultExecutionGraphQlService(source);
|
||||
this.dataLoaderRegistrars.forEach(service::addDataLoaderRegistrar);
|
||||
return service;
|
||||
return new TestExecutionGraphQlService(service);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,50 @@
|
||||
/*
|
||||
* Copyright 2002-2023 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.graphql;
|
||||
|
||||
public interface TestExecutionGraphQlService {
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Wrap an {@link ExecutionGraphQlService} to expose an addition convenience
|
||||
* method that takes a String document, and essentially hides the call to
|
||||
* {@link TestExecutionRequest#forDocument(String)}.
|
||||
*/
|
||||
public class TestExecutionGraphQlService implements ExecutionGraphQlService {
|
||||
|
||||
private final ExecutionGraphQlService delegate;
|
||||
|
||||
|
||||
public TestExecutionGraphQlService(ExecutionGraphQlService delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
public ExecutionGraphQlService getDelegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
public Mono<ExecutionGraphQlResponse> execute(String document) {
|
||||
ExecutionGraphQlRequest request = TestExecutionRequest.forDocument(document);
|
||||
return execute(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ExecutionGraphQlResponse> execute(ExecutionGraphQlRequest request) {
|
||||
return this.delegate.execute(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user