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.

fix(core): Respect additionalTypenames option on subscriptions (#3230)

authored by

Phil Pluckthun and committed by
GitHub
5134da88 f94f33fe

+18 -4
+5
.changeset/breezy-melons-deny.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Respect `additionalTypenames` on subscriptions and re-execute queries for them as well, as one would intuitively expect.
+13 -4
packages/core/src/exchanges/cache.ts
··· 114 114 let { operation } = response; 115 115 if (!operation) return; 116 116 117 - const typenames = collectTypesFromResponse(response.data).concat( 118 - operation.context.additionalTypenames || [] 119 - ); 117 + let typenames = operation.context.additionalTypenames || []; 118 + // NOTE: For now, we only respect `additionalTypenames` from subscriptions to 119 + // avoid unexpected breaking changes 120 + // We'd expect live queries or other update mechanisms to be more suitable rather 121 + // than using subscriptions as “signals” to reexecute queries. However, if they’re 122 + // just used as signals, it’s intuitive to hook them up using `additionalTypenames` 123 + if (response.operation.kind !== 'subscription') { 124 + typenames = collectTypesFromResponse(response.data).concat(typenames); 125 + } 120 126 121 127 // Invalidates the cache given a mutation's response 122 - if (response.operation.kind === 'mutation') { 128 + if ( 129 + response.operation.kind === 'mutation' || 130 + response.operation.kind === 'subscription' 131 + ) { 123 132 const pendingOperations = new Set<number>(); 124 133 125 134 dispatchDebug({