Skip to content

WebGraphQlTester Auto Config Improvements #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rstoyanchev opened this issue Jun 30, 2021 · 4 comments
Closed

WebGraphQlTester Auto Config Improvements #75

rstoyanchev opened this issue Jun 30, 2021 · 4 comments
Assignees
Labels
in: test Issues related to the test module in: web Issues related to web handling type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Jun 30, 2021

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.

@rstoyanchev rstoyanchev added type: enhancement A general enhancement in: web Issues related to web handling in: test Issues related to the test module labels Jun 30, 2021
@rstoyanchev rstoyanchev added this to the 1.0 M2 milestone Jun 30, 2021
@bclozel bclozel self-assigned this Jun 30, 2021
@rstoyanchev rstoyanchev modified the milestones: 1.0.0-M2, 1.0.0-M3 Aug 26, 2021
@bclozel
Copy link
Member

bclozel commented Oct 22, 2021

This is now fixed.

Looking at the table above, we're supporting now the following test profiles:

  • 1 is supported with @SpringBootTest + @AutoConfigureWebGraphQlTester + @AutoConfigureMockMvc
  • 2 is supported with @SpringBootTest + @AutoConfigureWebGraphQlTester + @AutoConfigureWebTestClient
  • 3 and 4 are supported with @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  • 5 and 6 are supported with @GraphQlTest

bclozel added a commit that referenced this issue Oct 22, 2021
@hantsy
Copy link
Contributor

hantsy commented Oct 23, 2021

Hope there is an option for testing WebSocket transport protocol on a live server.

@SpringBootTest + WebSocketClient(maybe a standalone GraphQlClient to choose HTTP or WebSocket)

@bclozel
Copy link
Member

bclozel commented Oct 23, 2021

What you're asking for is #163 - this issue is about making #163 (comment) simpler with @GraphQlTest.

@bclozel
Copy link
Member

bclozel commented Oct 27, 2021

Reopening for further refinements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues related to the test module in: web Issues related to web handling type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants