mirror of
https://github.com/zammad/zammad
synced 2026-05-24 09:48:36 +00:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
// Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
|
|
|
|
import { ApolloClient } from '@apollo/client/core'
|
|
|
|
import type { CacheInitializerModules } from '#shared/types/server/apollo/client.ts'
|
|
|
|
import createCache from './cache.ts'
|
|
import { clearSkipSubscriptionStore } from './link/skipSubscriptionResult.ts'
|
|
import link from './link.ts'
|
|
|
|
import type { NormalizedCacheObject } from '@apollo/client/core'
|
|
|
|
let apolloClient: ApolloClient<NormalizedCacheObject>
|
|
|
|
export const createApolloClient = (cacheInitializerModules: CacheInitializerModules = {}) => {
|
|
const cache = createCache(cacheInitializerModules)
|
|
|
|
apolloClient = new ApolloClient({
|
|
connectToDevTools: process.env.NODE_ENV !== 'production',
|
|
link,
|
|
cache,
|
|
queryDeduplication: true,
|
|
defaultOptions: {
|
|
// always refresh query results from the server
|
|
// https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy
|
|
watchQuery: {
|
|
fetchPolicy: 'cache-and-network',
|
|
nextFetchPolicy(currentFetchPolicy) {
|
|
return currentFetchPolicy
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
return apolloClient
|
|
}
|
|
|
|
export const getApolloClient = () => {
|
|
return apolloClient
|
|
}
|
|
|
|
export const clearApolloClientStore = async () => {
|
|
await apolloClient.clearStore()
|
|
|
|
// We clear also the skip subscription store on this situation.
|
|
clearSkipSubscriptionStore()
|
|
}
|