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

(core) - Fix stale on reexecute being skipped for cache-first (#1755)

* (core) - Fix stale on reexectuted operation being skipped for cache-first

* Fix stale reexecution logic being applied to subscriptions

Changed files
+21 -13
.changeset
packages
+5
.changeset/fresh-moose-exist.md
···
+
---
+
'@urql/core': patch
+
---
+
+
Fix accidental change in passive `stale: true`, where a `cache-first` operation issued by Graphcache wouldn't yield an affected query and update its result to reflect the loading state with `stale: true`. This is a regression from `v2.1.0` and mostly becomes unexpected when `cache.invalidate(...)` is used.
+10 -5
packages/core/src/client.test.ts
···
Source,
delay,
map,
+
never,
pipe,
+
merge,
subscribe,
publish,
filter,
···
it('does nothing when operation is a subscription has been emitted yet', () => {
const exchange: Exchange = () => ops$ => {
-
return pipe(
-
ops$,
-
map(op => ({ data: 1, operation: op })),
-
take(1)
-
);
+
return merge([
+
pipe(
+
ops$,
+
map(op => ({ data: 1, operation: op })),
+
take(1)
+
),
+
never,
+
]);
};
const client = createClient({
+6 -8
packages/core/src/client.ts
···
)
),
switchMap(result => {
-
if (result.stale) {
+
if (operation.kind !== 'query' || result.stale) {
return fromValue(result);
}
···
// Mark a result as stale when a new operation is sent for it
pipe(
operations$,
-
filter(op => {
-
return (
-
op.kind === operation.kind &&
+
filter(
+
op =>
+
op.kind === 'query' &&
op.key === operation.key &&
-
(op.context.requestPolicy === 'network-only' ||
-
op.context.requestPolicy === 'cache-and-network')
-
);
-
}),
+
op.context.requestPolicy !== 'cache-only'
+
),
take(1),
map(() => ({ ...result, stale: true }))
),