Add GraphQlTest annotation

Prior to this commit, we could only test Spring GraphQL applications
with a complete application - all application and infrastructure
components were involved. While using `@SpringBootTest` is often useful
for complete integration tests (with or without a live running server),
we often want to write lean integration tests and test slices of our
application.

Just like `@WebMvcTest` or `@WebFluxTest`, this commit introduces the
support for `@GraphQlTest`. This annotation helps us to test a
particular slice of our application: a hand-picked selection of
`@Controller`, plus `RuntimeWiringConfigurer` and `WebInterceptor`
beans.

Other `@Component` must be imported or mocked for those tests.

This commit also refactors the existing auto-configuration to enable
this use case. The `WebGraphQlHandlerAutoConfiguration` now holds the
required components for `@GraphQlTest`, while other web-related
auto-configurations bring the web framework and transport
infrastructures.

Closes gh-75
This commit is contained in:
Brian Clozel
2021-10-22 21:50:05 +02:00
parent 69e34baadf
commit e053e14158
27 changed files with 901 additions and 134 deletions

View File

@@ -24,8 +24,8 @@ import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Main entry point for testing GraphQL over a Web transport with requests
* executed {@link #create(WebTestClient) via WebTestClient} or
* {@link #create(WebGraphQlHandler) via WebGraphQlHandler}. See the below for
* examples with different scenarios.
* {@link #create(WebGraphQlHandler) via WebGraphQlHandler}.
*
*
* <p>
* GraphQL requests to Spring MVC without an HTTP server: <pre class="code">