Skip to content

Commit

Permalink
Cache exchange not forwarding teardown correctly urql-graphql#215
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobadini committed Apr 6, 2019
1 parent 4eada3b commit 7299621
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/exchanges/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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$]);
};
};

Expand Down

0 comments on commit 7299621

Please sign in to comment.