graphql-spring-boot
graphql-spring-boot copied to clipboard
GraphQLTestSubscription fails to init() when using @GraphQLTest
Describe the bug
GraphQLTestSubscription
fails to create a WebSocket connection in a test.
To Reproduce Steps to reproduce the behavior:
- Define a test class annotated with
@GraphQLTest
- Autowire the
GraphQLTestSubscription
dependency - call
init()
on the test subcription - See error:
Caused by: javax.websocket.DeploymentException: The HTTP response from the server [404] did not permit the HTTP upgrade to WebSocket
at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServerRecursive(WsWebSocketContainer.java:440)
at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:197)
at com.graphql.spring.boot.test.GraphQLTestSubscription.initClient(GraphQLTestSubscription.java:387)
Expected behavior
GraphQLTestSubscription
should establish the WebSocket connection without errors.
Additional context
I did notice that @GraphQLTest
does not seem to include GraphQLWebsocketAutoConfiguration
. However, importing it to the test context did not seem to fix the issue.
Until this is fixed, you can use @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
instead of @GraphQLTest
I could reproduce the issue with integration test. It seems that some necesary beans are missing when using @GraphQLTest
, even if GraphQLWebsocketAutoConfiguration
is added.
Number of beans
- when using
@GraphQLTest
- 100 ❌ - when using
@GraphQLTest
withGraphQLWebsocketAutoConfiguration
added - 106 ❌ - when using
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
- 277 ✔️