-
Notifications
You must be signed in to change notification settings - Fork 726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalised Cache Not Using Data from Different Query #3345
Comments
Hi @reubn – I took a quick look at your minimal test case, and I think that there's a bit of a mis-understanding of how the cache functions. Within your As you said, you're really looking for the Your fetch data function becomes something like this: func fetchData() {
GraphQL.shared.apollo.store.withinReadTransaction { transaction in
let countryInfo = try transaction.readObject(ofType: CountryInfo.self, withKey: "Country:\(code)")
self.country = countryInfo
}
} More important that having a fix (which may or may not work for your use-case) is understanding why what you're attempting to do fails. Imagine, for a moment, that your query CountryDetailQuery($code: ID!) {
country(code: $code) {
...CountryInfo
population
officialLanguage
currentLeader
governmentType
# etc
}
} At this point, there's a very clear divergence between the For example, a |
I'm closing this issue due to inactivity. If this is still unresolved, feel free to provide more information and we can re-open this, or create a new issue. |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better. |
Summary
I have a very simple use case that doesn't seem to be handled by the normalised cache properly.
I have a query that returns a list of
Country
s using aCountryInfo
fragment.I then have a second query that queries for a specific
Country
, returning the same fragment.The data returned for the first query populates the cache, but is not used for the second query. Apollo returns the following error.
I have set up custom cache keys, but Apollo seems to only correctly return cached data for the same query, despite the 2 pieces of data in the cache having the same cache key. This is unexpected.
By introspecting the
SQLiteNormalizedCache
database I can see that the data from the first query is stored and keyed correctly, but this not appear to be read in the second. The test case behaves identically with theInMemoryNormalizedCache
.I can see that a similar issue was reported #842, and if this behaviour is intentional then the question is: how can I implement cache redirects to normalise identical objects across queries?
Thanks!
Minimal test case: https://github.com/reubn/apolloiOSBugTestCase
Version
1.9.0
Steps to reproduce the behavior
Minimal test case: https://github.com/reubn/apolloiOSBugTestCase
Logs
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: