Skip to content
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

Add utility for testing components that use GraphQlClient #1144

Open
xenoterracide opened this issue Mar 5, 2025 · 3 comments
Open

Add utility for testing components that use GraphQlClient #1144

xenoterracide opened this issue Mar 5, 2025 · 3 comments
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged

Comments

@xenoterracide
Copy link

xenoterracide commented Mar 5, 2025

We're actively building a lot of code to integrate existing microservices into other services that are moving to a graphql interface. For now our services will remain REST. our services are "client only". What I'm looking for is an option akin to spring core's RestClientTest, where I can very quickly stub our limited responses with static responses. No idea for API at this time.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 5, 2025
@rstoyanchev
Copy link
Contributor

I'm not sure what RestClientTester is, but it sounds like MockRestServiceServer or based on it. There isn't anything exactly like that. However, you can use the same (i.e. MockRestServiceServer via RestClient/RestTemplate) to return canned GraphQL responses. It's just HTTP and doesn't necessarily need special handling, especially with canned responses.

You could also consider ExecutionGraphQlServiceTester, essentially GraphQlTester without a transport, and calling the GraphQL layer directly. You could add a little extra support around it to make it more convenient, like the MockExecutionGraphQlService that we use for own testing, for example here.

@xenoterracide
Copy link
Author

google in it's infinite wisdom is having problems locating the reference/example documentation to

https://docs.spring.io/spring-boot/api/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.html

baeldung has some though

https://www.baeldung.com/restclienttest-in-spring-boot

@xenoterracide xenoterracide changed the title Feature: GraphQlClientTester Feature: GraphQlClientTest Mar 6, 2025
@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 6, 2025
@bclozel
Copy link
Member

bclozel commented Mar 8, 2025

I guess we're mixing things a bit here: what we'd like to test and how we'd like to test it, what Spring GraphQL can do to help and if/how Spring Boot can provide a test slice for this case.

I think that reproducing @RestClientTest with a MockRestServiceServer HTTP setup is not buying us much and can be done already today. Maybe considering a MockExecutionGraphQlService that plugs into a testing GraphQlTransport would work. The main problem is that we have specialized interfaces like HttpSyncGraphQlClient and that we promote specific static factory methods to create those using RestClient or WebClient. Components under test would probably need to have dedicated constructors accepting GraphQlTransport as well, but I think that if we provide a high-level testing utility this should still be a better solution.

@bclozel bclozel changed the title Feature: GraphQlClientTest Add utility for testing components that use GraphQlClient Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants