Make ApolloStore an open extensible class, and its previously-internal dependencies public #509
+105
−89
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.
(This is in reference to apollographql/apollo-ios#3461, which I filed earlier today.)
The goal of this PR is: Make it easier to customize behavior of the Apollo normalized cache.
Currently, ApolloStore is a concrete class depended-on by lots of Apollo internals. It's not marked open, nor is it a protocol, so in practice there is no way without modifying Apollo code for applications to customize the store behavior.
With this PR, it is still necessary to use
@_spi(Execution)
for overriding particularly fiddly bits of ApolloStore behavior. I think this is probably a good thing to help users understand that they're digging deep into the internals, while still allowing us to customize the behavior we want.Feedback is welcome. In particular I'm not sure whether to do what Android does and make ApolloStore a protocol and rename the current
ApolloStore
toDefaultApolloStore
. I can make that change too if desired.Feel free to skip the below, but here's some more context about the why:
My specific use-case is one that has been touched-on/requested a number of places (apollographql/apollo-ios#3319, apollographql/apollo-ios#892, apollographql/apollo-ios#3216: make the Apollo cache accept missing values for nullable fields as null, rather than failing to parse them.) While Apollo team has resisted adding a flag, if ApolloStore were extensible I could implement the behavior I want myself without forking all of apollo-ios.
This example is what I was trying to write, impossible (as far as I can tell) without making ApolloStore extensible. It's just an ApolloStore that passes
.allowForOptionalFields
to theGraphQLSelectionSetMapper
during load: