diff --git a/packages/aws-appsync/src/client.ts b/packages/aws-appsync/src/client.ts index 26c4b2d4..52120f6e 100644 --- a/packages/aws-appsync/src/client.ts +++ b/packages/aws-appsync/src/client.ts @@ -28,14 +28,17 @@ import { createRetryLink } from './link/retry-link'; import { boundEnqueueDeltaSync, buildSync, DELTASYNC_KEY, hashForOptions } from "./deltaSync"; import { Subscription } from 'apollo-client/util/Observable'; import { PERMANENT_ERROR_KEY } from './link/retry-link'; +import { OfflineStatusChangeCallbackCreator } from './store'; +import defaultOfflineConfig from '@redux-offline/redux-offline/lib/defaults'; +const { detectNetwork: defaultDetectNetwork } = defaultOfflineConfig; export { defaultDataIdFromObject }; class CatchErrorLink extends ApolloLink { - + private link: ApolloLink; - + constructor(linkGenerator: () => ApolloLink) { try { super(); @@ -146,6 +149,7 @@ export interface AWSAppSyncClientOptions { cacheOptions?: ApolloReducerConfig, disableOffline?: boolean, offlineConfig?: OfflineConfig, + detectNetwork?: OfflineStatusChangeCallbackCreator, } export type OfflineConfig = Pick>, 'storage' | 'callback' | 'keyPrefix'> & { @@ -193,6 +197,7 @@ class AWSAppSyncClient extends Apollo callback = () => { }, storeCacheRootMutation = false, } = {}, + detectNetwork = defaultDetectNetwork, }: AWSAppSyncClientOptions, options?: Partial>) { const { cache: customCache = undefined, link: customLink = undefined } = options || {}; @@ -216,7 +221,8 @@ class AWSAppSyncClient extends Apollo dataIdFromObject, storage, keyPrefix, - callback + callback, + detectNetwork, }); const cache: ApolloCache = disableOffline ? (customCache || new InMemoryCache(cacheOptions)) diff --git a/packages/aws-appsync/src/store.ts b/packages/aws-appsync/src/store.ts index 892c96a8..f2cfc313 100644 --- a/packages/aws-appsync/src/store.ts +++ b/packages/aws-appsync/src/store.ts @@ -19,7 +19,6 @@ import { OfflineAction, NetInfo, NetworkCallback } from '@redux-offline/redux-of import { offlineEffectConfig as deltaSyncConfig } from "./deltaSync"; import { Observable } from 'apollo-link'; -const { detectNetwork } = defaultOfflineConfig; const logger = rootLogger.extend('store'); @@ -30,6 +29,7 @@ export type StoreOptions = { keyPrefix?: string, storage?: any, callback: OfflineCallback, + detectNetwork?: OfflineStatusChangeCallbackCreator }; export const DEFAULT_KEY_PREFIX = REDUX_PERSIST_KEY_PREFIX; @@ -41,6 +41,7 @@ const newStore = ({ keyPrefix, storage, callback = () => { }, + detectNetwork, }: StoreOptions): Store => { logger('Creating store'); @@ -83,9 +84,10 @@ const newStore = ({ store, clientGetter(), callback, - detectNetwork as OfflineStatusChangeCallbackCreator + detectNetwork ), discard: (error, action, retries) => discard(callback, error, action, retries), + detectNetwork }) ) );