Skip to content

Commit

Permalink
fix(core): return a result in cache-only scenarios (#3459)
Browse files Browse the repository at this point in the history
Co-authored-by: Phil Pluckthun <phil@kitten.sh>
  • Loading branch information
JoviDeCroock and kitten authored Dec 12, 2023
1 parent 0af6e54 commit d5d3c97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/three-pandas-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/core': patch
---

Fix the default `cacheExchange` crashing on `cache-only` request policies with cache misses due to `undefined` results.
8 changes: 7 additions & 1 deletion packages/core/src/exchanges/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
addMetadata,
collectTypenames,
formatDocument,
makeResult,
} from '../utils';

type ResultCache = Map<number, OperationResult>;
Expand Down Expand Up @@ -79,7 +80,12 @@ export const cacheExchange: Exchange = ({ forward, client, dispatchDebug }) => {
}),
});

let result: OperationResult = cachedResult!;
let result: OperationResult =
cachedResult ||
makeResult(operation, {
data: null,
});

if (process.env.NODE_ENV !== 'production') {
result = {
...result,
Expand Down

0 comments on commit d5d3c97

Please sign in to comment.