From 7299621389f287eec0b018809806a68fa1b87dce Mon Sep 17 00:00:00 2001 From: federicobadini Date: Sun, 7 Apr 2019 01:02:46 +0200 Subject: [PATCH] Cache exchange not forwarding teardown correctly #215 --- src/exchanges/cache.ts | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/exchanges/cache.ts b/src/exchanges/cache.ts index 31fc099683..0d32c33e5c 100755 --- a/src/exchanges/cache.ts +++ b/src/exchanges/cache.ts @@ -73,27 +73,35 @@ export const cacheExchange: Exchange = ({ forward, client }) => { }) ); - const newOps$ = pipe( - sharedOps$, - filter(op => !shouldSkip(op) && !isOperationCached(op)), - map(mapTypeNames), + const forwardedOps$ = pipe( + merge([ + pipe( + sharedOps$, + filter(op => !shouldSkip(op) && !isOperationCached(op)), + map(mapTypeNames) + ), + pipe( + sharedOps$, + filter(op => shouldSkip(op)) + ), + ]), forward, tap(response => { - if (response.operation.operationName === 'mutation') { + if ( + response.operation && + response.operation.operationName === 'mutation' + ) { handleAfterMutation(response); - } else if (response.operation.operationName === 'query') { + } else if ( + response.operation && + response.operation.operationName === 'query' + ) { handleAfterQuery(response); } }) ); - const skippedOps$ = pipe( - sharedOps$, - filter(op => shouldSkip(op)), - forward - ); - - return merge([cachedOps$, newOps$, skippedOps$]); + return merge([cachedOps$, forwardedOps$]); }; };