Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add option to let subscriptionExchange handle all operations (#544)

* Add option to subscriptionExchange to enable all ops

* Add changeset

* Fix missing boolean cast

authored by

Phil Plückthun and committed by
GitHub
0c5c1fdc 8877e0fb

+16 -3
+5
.changeset/tiny-goats-type.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Add enableAllOperations option to subscriptionExchange to let it handle queries and mutations as well.
+11 -3
packages/core/src/exchanges/subscription.ts
··· 52 52 // This has been modelled to work with subscription-transport-ws 53 53 // See: https://github.com/apollographql/subscriptions-transport-ws#requestoptions--observableexecutionresult-returns-observable-to-execute-the-operation 54 54 forwardSubscription: SubscriptionForwarder; 55 + 56 + /** This flag may be turned on to allow your subscriptions-transport to handle all operation types */ 57 + enableAllOperations?: boolean; 55 58 } 56 59 57 - const isSubscriptionOperation = (operation: Operation) => 58 - operation.operationName === 'subscription'; 59 - 60 60 export const subscriptionExchange = ({ 61 61 forwardSubscription, 62 + enableAllOperations, 62 63 }: SubscriptionExchangeOpts): Exchange => ({ client, forward }) => { 63 64 const createSubscriptionSource = ( 64 65 operation: Operation ··· 100 101 if (sub) sub.unsubscribe(); 101 102 }; 102 103 }); 104 + }; 105 + 106 + const isSubscriptionOperation = (operation: Operation): boolean => { 107 + const { operationName } = operation; 108 + return operationName === 'subscription' || 109 + (!!enableAllOperations && 110 + (operationName === 'query' || operationName === 'mutation')); 103 111 }; 104 112 105 113 return ops$ => {