Posting a new thread about the use-case for the ab...
# apollo-kotlin
s
Posting a new thread about the use-case for the above post to keep it more organized 🧵
šŸ™ 1
We have a test suite which in 2.x relied on mocking a map of requests to responses using their string representations of how the query looked like (QUERY_DOCUMENT before, OPERATION_DOCUMENT now) mapped to their Operation.Data. This can be seen here for example. Before, this was mapped to json here using some MergingResponseWriter and as you can see it also uses the marshaler which both are things I can’t directly use in 3.x so I have been trying to simply look for alternatives. So I’m trying to make it work while not changing how all the tests are written, so I am met with trying to go from Operation.Data -> json representation without having an instance of the Operation, in order to take that json response and put it inside the MockServer as the return value Now I’ve also looked into using the new testing capabilities from the library which I thought were very interesting, and I did try to make it work as shown here (I might still look into this later after we at least got the app running while using Apollo 3.x) but it turns out we are doing some tests without even using the generated code from apollo and the tests were doing some tricks to handle queries that take parameters and have those be part of the response by manually extracting them here, and providing them to the response here. So I’ve just been trying to make it all work while still keeping the same test API basically and this has not been easy during this migration since we’re doing a lot of ā€œweirdā€ stuff I guess šŸ˜„ And I am like certain there’s probably stuff that could be simplified if we re-wrote this whole thing, but I am trying to at least try to get it work first so that I have the confidence to do some bigger changes.
m
Gotcha! Migration is a good use case indeed. I'm hoping that because 2.x was mostly android, the
toJson()
that uses reflection can be a good-enough solution there.
šŸ‘ 1
In the long run, I'd like the Test Builders to provide a better alternative there
Looking at your tests, looks like sometimes you enqueue
jsonObject
in the mock server and other times
data
. Ideally,
ApolloMockServerResponseBuilder
always work at the Json level and I'm hoping https://github.com/apollographql/apollo-kotlin/issues/3851 could provide a solution there
Thanks for providing this, that helps a ton!
šŸ¤— 1
s
Yeah we have an API to provide JSONObject and another for Data, but in the end they both turn into a String (here I’ll use the toJsonString) which should be the json representation of them and are being put inside the MockResponse. We also have a ton of code where we’re building all those responses ourselves. Basically everything in here, it’s thousands and thousands of lines 😭 I’d love, again; after I make sure the migrated code works, to try out the test builders to do this instead.