Is there a wildcard for declaring all entities custom keyFields in the typePolicies?

When creating a new InMemoryCache is there a way to say

 "*": {
      keyFields: ["uuid"],
    },

instead of

 Entity1: {
      keyFields: ["uuid"],
    },
 Entity2: {
      keyFields: ["uuid"],
    },
 Entity3: {
      keyFields: ["uuid"],
    },

Hey @Ma-ft :wave:!

Take a look at the dataIdFromObject API. This might be what you’re looking for as it allows you to define global fallback cache ID.

1 Like

Thanks i ended up going with below

import { defaultDataIdFromObject } from '@apollo/client';

const cache = new InMemoryCache({
  dataIdFromObject: (r) => {
    if (r.__typename) {
      return (r.uuid as unknown) as string;
    }
    return defaultDataIdFromObject(r);
  },
});

now i can just focus on explicit typePolicies for outlier Entities :+1:

1 Like