@@ -17,7 +17,7 @@ import { NORMALIZED_CACHE_KEY, METADATA_KEY } from "../cache";
17
17
import { AWSAppsyncGraphQLError } from "../types" ;
18
18
import { Store } from "redux" ;
19
19
import { OfflineCache , AppSyncMetadataState } from "../cache/offline-cache" ;
20
- import { isUuid , getOperationFieldName } from "../utils" ;
20
+ import { isUuid , getOperationFieldName , rootLogger } from "../utils" ;
21
21
import AWSAppSyncClient from ".." ;
22
22
import { ApolloCache } from "apollo-cache" ;
23
23
import { MutationUpdaterFn , MutationQueryReducersMap , ApolloError } from "apollo-client" ;
@@ -26,6 +26,8 @@ import { OfflineCallback } from "../client";
26
26
import { SKIP_RETRY_KEY } from "./retry-link" ;
27
27
import { OfflineEffectConfig } from "../store" ;
28
28
29
+ const logger = rootLogger . extend ( 'offline-link' ) ;
30
+
29
31
const actions = {
30
32
SAVE_SNAPSHOT : 'SAVE_SNAPSHOT' ,
31
33
ENQUEUE : 'ENQUEUE_OFFLINE_MUTATION' ,
@@ -185,10 +187,6 @@ const enqueueMutation = <T>(operation: Operation, theStore: Store<OfflineCache>,
185
187
return result ;
186
188
}
187
189
188
- interface CanBeSilenced < TCache > extends ApolloCache < TCache > {
189
- silenceBroadcast ?: boolean
190
- } ;
191
-
192
190
const effect = async < TCache extends NormalizedCacheObject > (
193
191
store : Store < OfflineCache > ,
194
192
client : AWSAppSyncClient < TCache > ,
@@ -197,7 +195,6 @@ const effect = async <TCache extends NormalizedCacheObject>(
197
195
callback : OfflineCallback ,
198
196
) : Promise < FetchResult < Record < string , any > , Record < string , any > > > => {
199
197
const doIt = true ;
200
- const { cache } : { cache : CanBeSilenced < TCache > } = client ;
201
198
const {
202
199
optimisticResponse : origOptimistic ,
203
200
operation : { variables : origVars , query : mutation , context } ,
@@ -232,6 +229,7 @@ const effect = async <TCache extends NormalizedCacheObject>(
232
229
} ;
233
230
const operation = buildOperationForLink . call ( client . queryManager , mutation , variables , extraContext ) ;
234
231
232
+ logger ( 'Executing link' , operation ) ;
235
233
execute ( client . link , operation ) . subscribe ( {
236
234
next : data => {
237
235
boundSaveServerId ( store , optimisticResponse , data . data ) ;
@@ -274,13 +272,16 @@ const effect = async <TCache extends NormalizedCacheObject>(
274
272
} = effect as EnqueuedMutationEffect < any > ;
275
273
276
274
if ( typeof update !== 'function' ) {
275
+ logger ( 'No update function for mutation' , { document, variables } ) ;
277
276
return ;
278
277
}
279
278
280
279
const optimisticResponse = replaceUsingMap ( { ...origOptimisticResponse } , idsMap ) ;
281
280
const result = { data : optimisticResponse } ;
282
281
283
282
if ( fetchPolicy !== 'no-cache' ) {
283
+ logger ( 'Running update function for mutation' , { document, variables } ) ;
284
+
284
285
dataStore . markMutationResult ( {
285
286
mutationId : null ,
286
287
result,
@@ -334,7 +335,7 @@ const effect = async <TCache extends NormalizedCacheObject>(
334
335
}
335
336
} ,
336
337
error : err => {
337
- // TODO: Undo cache updates?
338
+ logger ( 'Error when executing link' , err ) ;
338
339
339
340
reject ( err ) ;
340
341
}
@@ -450,14 +451,10 @@ const discard = (callback: OfflineCallback, error, action, retries) => {
450
451
451
452
if ( discardResult ) {
452
453
// Call global error callback or observer
453
- try {
454
- if ( typeof callback === 'function' ) {
455
- tryFunctionOrLogError ( ( ) => {
456
- callback ( { error } , null ) ;
457
- } ) ;
458
- }
459
- } catch ( error ) {
460
- // TODO: warn
454
+ if ( typeof callback === 'function' ) {
455
+ tryFunctionOrLogError ( ( ) => {
456
+ callback ( { error } , null ) ;
457
+ } ) ;
461
458
}
462
459
}
463
460
@@ -468,15 +465,15 @@ const _discard = (error, action: OfflineAction, retries) => {
468
465
const { graphQLErrors = [ ] } : { graphQLErrors : AWSAppsyncGraphQLError [ ] } = error ;
469
466
470
467
if ( graphQLErrors . length ) {
471
- // console.error ('Discarding action.', action, graphQLErrors);
468
+ logger ( 'Discarding action.' , action , graphQLErrors ) ;
472
469
473
470
return true ;
474
471
} else {
475
472
const { networkError : { graphQLErrors = [ ] } = { graphQLErrors : [ ] } } = error ;
476
473
const appSyncClientError = graphQLErrors . find ( err => err . errorType && err . errorType . startsWith ( 'AWSAppSyncClient:' ) ) ;
477
474
478
475
if ( appSyncClientError ) {
479
- // console.error ('Discarding action.', action, appSyncClientError);
476
+ logger ( 'Discarding action.' , action , appSyncClientError ) ;
480
477
481
478
return true ;
482
479
}
0 commit comments