registerIncomingMerge.ts 777 B

123456789101112131415161718192021222324
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { InMemoryCacheConfig } from '@apollo/client/cache/inmemory/types'
  3. // If a new array is returned and length differs, cache doesn't like it,
  4. // and we need to tell apollo that it needs to just replace current state altogether
  5. // this should be used only, if you are not using pagination.
  6. export default function registerIncomingMerge(
  7. config: InMemoryCacheConfig,
  8. queryName: string,
  9. fields?: string[],
  10. ): InMemoryCacheConfig {
  11. config.typePolicies ||= {}
  12. config.typePolicies.Query ||= {}
  13. config.typePolicies.Query.fields ||= {}
  14. config.typePolicies.Query.fields[queryName] = {
  15. keyArgs: fields,
  16. merge(_, incoming) {
  17. return incoming
  18. },
  19. }
  20. return config
  21. }