How to use the apollo-client-preset.defaultDataIdFromObject function in apollo-client-preset

To help you get started, we’ve selected a few apollo-client-preset examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github metaspace2020 / metaspace / metaspace / webapp / src / lib / apolloCache.ts View on Github external
dataIdFromObject(object: any) {
    // WORKAROUND: Because of Apollo's aggressive caching, often the current User will be overwritten with results
    // from other queries. The server side often strips fields based on how they're accessed (the "ScopeRole" logic),
    // which means these query paths will often return different data with the same IDs:
    // currentUser -> primaryGroup (always present)
    // dataset -> submitter -> primaryGroup (null unless admin)
    // To protect against this, don't allow Users (and possibly other types in the future) to have a dataId,
    // so that InMemoryCache cannot share data between different queries.
    if (nonNormalizableTypes.includes(object.__typename)) {
      return null
    } else {
      return defaultDataIdFromObject(object)
    }
  },
})