Skip to content

Commit ef36cea

Browse files
committed
Create less promises in GraphQL.operate() when the reloadOnLoad and reloadOnLoad options are false.
1 parent 8ff1427 commit ef36cea

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Improved the test utility `promisifyEvent` function.
1919
- Test the `GraphQL.operate()` option `reloadOnLoad` in isolation.
2020
- Test better the order of `GraphQL.operate()` triggered events.
21+
- Reduced the number of promises created by `GraphQL.operate()` when the `reloadOnLoad` and `reloadOnLoad` options are `false`.
2122
- Added a code example for how to await all loading GraphQL operations.
2223
- Used consistent JSDoc types for promises that resolve `void`.
2324

src/universal/GraphQL.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,15 @@ module.exports = class GraphQL {
305305
const cacheKey = cacheKeyCreator(fetchOptions);
306306
const cacheValuePromise = this.fetch(fetchOptions, cacheKey);
307307

308-
// Potential edge-case issue: Multiple identical queries with `resetOnLoad`
309-
// enabled will cause excessive resets.
310-
cacheValuePromise.then(() => {
311-
if (reloadOnLoad) this.reload(cacheKey);
312-
else if (resetOnLoad) this.reset(cacheKey);
313-
});
308+
// A reload or reset happens after the cache is updated as a side effect.
309+
if (reloadOnLoad)
310+
cacheValuePromise.then(() => {
311+
this.reload(cacheKey);
312+
});
313+
else if (resetOnLoad)
314+
cacheValuePromise.then(() => {
315+
this.reset(cacheKey);
316+
});
314317

315318
return {
316319
cacheKey,

0 commit comments

Comments
 (0)