Open
Description
Summary
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 launches:
query LaunchList {
launches {
launches {
id
site
mission {
name
missionPatch(size: SMALL)
}
}
}
}
I then have a second query that queries for a specific launch:
query LaunchDetails($launchId: ID!) {
launch(id: $launchId) {
id
site
mission {
name
missionPatch(size: SMALL)
}
}
}
The data returned for the first query populates the cache, but is not used for the second query.
I have set up custom cache keys in the SchemaConfiguration.swift:
import ApolloAPI
public enum SchemaConfiguration: ApolloAPI.SchemaConfiguration {
public static func cacheKeyInfo(for type: Object, object: ObjectData) -> CacheKeyInfo? {
if type.typename == "Launch", let id = object["id"] as? String {
let cacheKeyInfo = CacheKeyInfo(
id: id,
uniqueKeyGroup: type.typename
)
print("DEBUG: Generated cache key: \(cacheKeyInfo)")
return cacheKeyInfo
}
return nil
}
}
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. I get his log:
DEBUG: Generated cache key: CacheKeyInfo(id: "110", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "109", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "108", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "107", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "106", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "105", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "104", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "103", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "102", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "101", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "100", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "99", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "98", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "97", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "96", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "95", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "94", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "93", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "92", uniqueKeyGroup: Optional("Launch"))
DEBUG: Generated cache key: CacheKeyInfo(id: "91", uniqueKeyGroup: Optional("Launch"))
"LaunchListQuery Data came from the NETWORK"
DEBUG: Generated cache key: CacheKeyInfo(id: "110", uniqueKeyGroup: Optional("Launch"))
"LaunchDetailsQuery Data for launchID:110 came from the NETWORK"
I was under the impression that If I assign an id and same uniqueKeyGroup these would work?
Version
1.18.0
Steps to reproduce the behavior
Minimal test case: https://github.com/comontes/ApolloiOSBug1
Logs
Anything else?
No response