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.

feat(persisted): add option to enable persisted subscriptions (BACKPORT) (#3550)

authored by

Jovi De Croock and committed by
GitHub
a938b342 3692842e

+21 -2
+1 -1
examples/with-apq/package.json
··· 7 7 }, 8 8 "dependencies": { 9 9 "@urql/core": "^4.3.0", 10 - "@urql/exchange-persisted": "^4.1.1", 10 + "@urql/exchange-persisted": "^4.2.0", 11 11 "graphql": "^16.6.0", 12 12 "react": "^18.2.0", 13 13 "react-dom": "^18.2.0",
+7
exchanges/persisted/CHANGELOG.md
··· 1 1 # @urql/exchange-persisted-fetch 2 2 3 + ## 4.2.0 4 + 5 + ### Minor Changes 6 + 7 + - Add option to enable persisted-operations for subscriptions 8 + Submitted by [@JoviDeCroock](https://github.com/JoviDeCroock) (See [#3549](https://github.com/urql-graphql/urql/pull/3549)) 9 + 3 10 ## 4.1.1 4 11 5 12 ### Patch Changes
+1 -1
exchanges/persisted/package.json
··· 1 1 { 2 2 "name": "@urql/exchange-persisted", 3 - "version": "4.1.1", 3 + "version": "4.2.0", 4 4 "description": "An exchange that allows for persisted queries support when fetching queries", 5 5 "sideEffects": false, 6 6 "homepage": "https://formidable.com/open-source/urql/docs/",
+12
exchanges/persisted/src/persistedExchange.ts
··· 89 89 * their GraphQL APIs. 90 90 */ 91 91 enableForMutation?: boolean; 92 + /** Enables persisted queries to be used for subscriptions. 93 + * 94 + * @remarks 95 + * When enabled, the `persistedExchange` will also use the persisted queries 96 + * logic for subscription operations. 97 + * 98 + * This is disabled by default, but often used on APIs that obfuscate 99 + * their GraphQL APIs. 100 + */ 101 + enableForSubscriptions?: boolean; 92 102 } 93 103 94 104 /** Exchange factory that adds support for Persisted Queries. ··· 131 141 const enforcePersistedQueries = !!options.enforcePersistedQueries; 132 142 const hashFn = options.generateHash || hash; 133 143 const enableForMutation = !!options.enableForMutation; 144 + const enableForSubscriptions = !!options.enableForSubscriptions; 134 145 let supportsPersistedQueries = true; 135 146 136 147 const operationFilter = (operation: Operation) => 137 148 supportsPersistedQueries && 138 149 !operation.context.persistAttempt && 139 150 ((enableForMutation && operation.kind === 'mutation') || 151 + (enableForSubscriptions && operation.kind === 'subscription') || 140 152 operation.kind === 'query'); 141 153 142 154 const getPersistedOperation = async (operation: Operation) => {