registerNotNormalizedObjectFieldsMerge.ts 871 B

1234567891011121314151617181920212223242526
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { TypePolicy } from '@apollo/client/cache'
  3. import type { InMemoryCacheConfig } from '@apollo/client/cache/inmemory/types'
  4. // You can use a merge function to intelligently combine nested objects that
  5. // are not normalized in your cache, assuming those objects are nested within the same normalized parent.
  6. export default function registerNotNormalizedObjectFieldsMerge(
  7. config: InMemoryCacheConfig,
  8. type: string,
  9. fields: string[],
  10. ): InMemoryCacheConfig {
  11. const notNormalizedFields: Record<string, TypePolicy> = {}
  12. fields.forEach((field) => {
  13. notNormalizedFields[field] = {
  14. merge: (_, incoming) => incoming,
  15. }
  16. })
  17. config.typePolicies ||= {}
  18. config.typePolicies[type] ||= {}
  19. config.typePolicies[type].fields = notNormalizedFields
  20. return config
  21. }