Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

GraphQLTestAutoConfiguration tries to autowire TestRestTemplate regardless of WebEnvironment #544

Closed
lassemaatta opened this issue Feb 23, 2021 · 5 comments · Fixed by #617
Labels
Milestone

Comments

@lassemaatta
Copy link

Describe the bug
When the GraphQLTestAutoConfiguration class attempts to initialize the graphQLTestUtils bean, a NoSuchBeanDefinitionException is thrown because TestRestTemplate could not be autowired.

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple working Spring application
  2. Add tests using @SpringBootTest (aka. with webEnvironment = WebEnvironment.MOCK) and check that they run
  3. Add dependency to graphql-spring-boot-starter and graphql-spring-boot-starter-test
  4. Notice how existing tests now fail to start due to NoSuchBeanDefinitionException

Expected behavior
Adding the graphql dependencies should not break existing tests.

Additional context
A workaround is to explicitly disable graphql for the existing tests, using eg. @SpringBootTest(properties = "graphql.servlet.enabled=false")

@streibeb
Copy link

streibeb commented Mar 5, 2021

I have this exact same issue, however your workaround doesn't work for me as I get another error:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphQLWebsocketServlet' defined in class path resource [graphql/kickstart/spring/web/boot/GraphQLWebsocketAutoConfiguration.class]: Unsatisfied dependency expressed through method 'graphQLWebsocketServlet' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'graphql.kickstart.execution.subscriptions.GraphQLSubscriptionInvocationInputFactory' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

@lassemaatta
Copy link
Author

@streibeb have you tried also setting graphql.servlet.websocket to false? That property is used by the GraphQLWebsocketAutoConfiguration class.

@SpringBootTest(properties = {
        "graphql.servlet.enabled=false",
        "graphql.servlet.websocket.enabled=false"
})

@streibeb
Copy link

@lassemaatta That worked, thank you!

@dhasilin
Copy link

+1
Issue might be also be caused by
@ConditionalOnProperty(value = "graphql.servlet.enabled", havingValue = "true", matchIfMissing = true)

Slightly nicer approach for now is to disable auto config in general configuration file:
@EnableAutoConfiguration(exclude = {GraphQLTestAutoConfiguration.class})

After that you could create local config with GraphQL enabled

@debu999
Copy link

debu999 commented Apr 9, 2021

with com.graphql-java-kickstart.graphiql-spring-boot-starter:11.0.0 and com.graphql-java-kickstart.graphql-spring-boot-starter-test:11.0.0 we only need to add
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Voila it works as expected. We can have something else done either. Not sure why the above just work without the property change.

@oliemansm oliemansm added this to the 12.0.0 milestone May 8, 2021
@oliemansm oliemansm linked a pull request May 8, 2021 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants