-
Notifications
You must be signed in to change notification settings - Fork 328
Description
After recent changes in #65 to create a WebGraphQlTester as a sub-type of GraphQlTester, there are now three ways to create a tester, performing requests through WebTestClient, WebGraphQlHandler, or GraphQlService which gives the following possibilities:
| Perform Requests | Server | Starter | |
|---|---|---|---|
| 1. | WebTestClient | WebMvc handling only, no running server (MockMvc) | starter-webmvc |
| 2. | WebTestClient | WebFlux handling only, no running server | starter-webflux |
| 3. | WebTestClient | Live server | starter-webmvc |
| 4. | WebTestClient | Live server | starter-webflux |
| 5. | WebGraphQlHandler | WebInterceptor chain only, no web framework | starter-webmvc |
| 6. | WebGraphQlHandler | WebInterceptor chain only, no web framework | starter-webflux |
| 7. | GraphQlService | GraphQL Java, no web layer | starter-webmvc |
| 8. | GraphQlService | GraphQL Java, no web layer | starter-webflux |
1-4 are the most likely choice for GraphQL over HTTP tests. 5-6, as well as 7-8, can be used to test subscriptions without WebSocket and that's useful because we don't yet support testing GraphQL over WebSocket.
If applications declare @SpringBootTest, @AutoConfigureGraphQlTester, and either @AutoConfigureMockMvc or @AutoConfigureWebTestClient they get WebGraphQlTester created with WebTestClient, i.e. 1-4.
If however @AutoConfigureMockMvc or @AutoConfigureWebTestClient are left out, applications get WebGraphQlTester created with WebGraphQlHandler, i.e. 5-6.
This makes sense overall but it can lead to issues, e.g. where you end up with 5-6 (no web framework) by accident, simply because you maybe forgot to declare @AutoConfigureMockMvc or @AutoConfigureWebTestClient. Now it may appear to work but if you rely on WebTestClient, and likewise the web framework, to be pre-configured for Spring Security, then you're missing an essential part of the setup.
We should consider ways to make the tester auto config so that the choices are more explicit, and likewise more intuitive if no explicit choices are made. This could mean for example that the combination of @SpringBootTest and @AutoConfigureGraphQlTester give the most complete, and intuitive choice, in this case one of 1-4 by default, but you can otherwise override this by choosing an enum attribute on @AutoConfigureGraphQlTester for "web interceptor chain" or "graphql service" only.