apollo-feature-requests
apollo-feature-requests copied to clipboard
Key an object in the cache by multiple keys
Migrated from: apollographql/apollo-client#1934
I have the exact same use the @mxstbr reported and would love to see this! Has there been any progress on it or is it planned in an upcoming release?
We are planning to consolidate dataIdFromObject
, the @connection
directive, and cacheRedirects
(FKA customResolvers
) in the next major version of Apollo Client (3.0). I will definitely keep this feature request in mind, since I agree that multiple and/or composite primary keys are essential to many use cases.
Exact same use case here. I've just checked-out the preview of Apollo Client. Seems that this feature will be supported:
const cache = new InMemoryCache({
typePolicies: {
Book: {
keyFields: ["isbn"],
},
},
});
This API supports multiple primary keys and composite primary keys, without any risk of unstable JSON serialization, or forgetting to include the __typename in the ID.
👏
Would somebody please direct me to the official documentation page of this new feature in the preview version?
Any feedback on this? I did not find in the doc a way to have multiple primary keys (not composite key) My use case is the same as the original request
also was looking for an in library solution to this, ditto that it is an important feature
Would also like this. Note that the suggestion above that giving an array to keyFields
results in multiple primary keys is inaccurate - it just results in a composite key. From current docs:
Each TypePolicy's keyFields array defines which fields on the type together represent the type's primary key.
My assumption at this point is that multiple primary keys is still not currently possible.