Hey all, I am writing an integration test for a se...
# apollo-kotlin
r
Hey all, I am writing an integration test for a service that contacts another service using graphql with apollo client. What is the best approach for mocking the service? Is a regular http mock server a reasonable approach? I’ll mention that the test is dockerized. Thanks!
m
MockServer is what we do for apollo-kotlin codebase. It's working great đź‘Ť. There's even an
apollo-mockserver
artifact if you need native/js support
If not OkHttp MockWebServer has more features
r
I am also trying to use MockServer. My mock container name is managementmock, so I configure ApolloClient’s server url to be http://managementmock:1080. However, I get a connection refused error, and it seems that for some reason the ip is added to the url. I attached an image, do you have a clue why that might happen?
m
1080
is the port. IIRC it's assigned automatically, you don't have control over it. You should retrieve the url from the mock server:
Copy code
ApolloClient.Builder()
.serverUrl(mockServer.url())
.build()
Note that
url
is suspend so if you're in a plain Java project, you'd better use okhttp MockWebServer instead, it'll be easier to work with
r
thanks, it works!