https://kotlinlang.org logo
#apollo-kotlin
Title
# apollo-kotlin
r

Ron Aharoni

01/29/2023, 6:47 AM
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

mbonnin

01/29/2023, 8:49 AM
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

Ron Aharoni

01/29/2023, 10:44 AM
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

mbonnin

01/29/2023, 10:47 AM
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

Ron Aharoni

01/30/2023, 1:04 PM
thanks, it works!
6 Views