Skip to content

Commit

Permalink
fix(core): Always exclude teardowns from subscriptionExchange (#3206)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed May 3, 2023
1 parent 67c991f commit 351d3ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-geese-switch.md
@@ -0,0 +1,5 @@
---
'@urql/core': patch
---

Don't allow `isSubscriptionOperation` option in `subscriptionExchange` to include `teardown` operations, to avoid confusion.
24 changes: 15 additions & 9 deletions packages/core/src/exchanges/subscription.ts
Expand Up @@ -186,20 +186,22 @@ export const subscriptionExchange =
};
});
};

const isSubscriptionOperationFn =
isSubscriptionOperation ||
(operation => {
const { kind } = operation;
return (
kind === 'subscription' ||
(!!enableAllOperations && (kind === 'query' || kind === 'mutation'))
);
});
(operation =>
operation.kind === 'subscription' ||
(!!enableAllOperations &&
(operation.kind === 'query' || operation.kind === 'mutation')));

return ops$ => {
const subscriptionResults$ = pipe(
ops$,
filter(isSubscriptionOperationFn),
filter(
operation =>
operation.kind !== 'teardown' &&
isSubscriptionOperationFn(operation)
),
mergeMap(operation => {
const { key } = operation;
const teardown$ = pipe(
Expand All @@ -216,7 +218,11 @@ export const subscriptionExchange =

const forward$ = pipe(
ops$,
filter(op => !isSubscriptionOperationFn(op)),
filter(
operation =>
operation.kind === 'teardown' ||
!isSubscriptionOperationFn(operation)
),
forward
);

Expand Down

0 comments on commit 351d3ef

Please sign in to comment.