Make fetch(cachePolicy:)
public
in GraphQLQueryWatcher
so ApolloClientProtocol.watch
can be mocked.
#559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am implementing a
MockApolloClient
. It implementsApolloClientProtocol
. I got to the point of implementingwatch(query:cachePolicy:context:callbackQueue:resultHandler:)
.Looking at
ApolloClient
's implementation, it's very simple:It is basically implemented by passing
self
toGraphQLQueryWatcher
, which interacts with thatApolloClientProtocol
instance.As far as I can see, the best way to implement
watch
in myMockApolloClient
is by having basically the exact same code. I would pass inself
(being theMockApolloClient: ApolloClientProtocol
) into theGraphQLQueryWatcher
initializer, callfetch(cachePolicy:)
on it, and then return it.However,
fetch(cachePolicy:)
is notpublic
onGraphQLQueryWatcher
, it'sinternal
, so I can't do that.I suspect this is a simple oversight.
I don't think it makes sense to re-implement
GraphQLQueryWatcher
, it'd be better to have the same logic powering watching in theMockApolloClient
because it can operate in terms of the mock implementation ofApolloClientProtocol.fetch
andApolloClientProtocol.store
. And frankly, it'd be impossible to do anything else because theApolloClientProtocol.watch
method is declared as returningGraphQLQueryWatcher
, andGraphQLQueryWatcher
itself ispublic
, notopen
(just likeApolloClient
itself), so the only thing I can possibly do is useGraphQLQueryWatcher
, and that means needing to use its implementation as-is.As such, this PR makes
fetch(cachePolicy:)
public
. That's all it does.Thank you for your consideration.