apollo-feature-requests icon indicating copy to clipboard operation
apollo-feature-requests copied to clipboard

Key an object in the cache by multiple keys

Open LennardWesterveld opened this issue 5 years ago • 7 comments

Migrated from: apollographql/apollo-client#1934

LennardWesterveld avatar Dec 06 '18 19:12 LennardWesterveld

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?

lamflam avatar Jan 10 '19 19:01 lamflam

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.

benjamn avatar Jun 06 '19 19:06 benjamn

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.

👏

poulainv avatar Nov 20 '19 11:11 poulainv

Would somebody please direct me to the official documentation page of this new feature in the preview version?

geekox86 avatar Mar 01 '20 10:03 geekox86

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

bboure avatar Jun 18 '20 15:06 bboure

also was looking for an in library solution to this, ditto that it is an important feature

sanpablomarket avatar Jun 26 '20 16:06 sanpablomarket

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.

vigie avatar Jan 26 '21 19:01 vigie