@apollo/client 3.4.0-rc.7 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs.js +300 -263
- package/apollo-client.cjs.js.map +1 -1
- package/apollo-client.cjs.min.js +1 -1
- package/cache/cache.cjs.js +105 -41
- package/cache/cache.cjs.js.map +1 -1
- package/cache/core/types/DataProxy.js +1 -0
- package/cache/index.d.ts +0 -1
- package/cache/index.d.ts.map +1 -1
- package/cache/index.js +3 -1
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +3 -2
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js +22 -10
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/fixPolyfills.native.js +1 -0
- package/cache/inmemory/helpers.d.ts +1 -1
- package/cache/inmemory/helpers.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +5 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +24 -3
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/object-canon.d.ts +3 -1
- package/cache/inmemory/object-canon.d.ts.map +1 -1
- package/cache/inmemory/object-canon.js +12 -7
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +23 -10
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +5 -2
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +9 -6
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.js +1 -0
- package/cache/inmemory/writeToStore.d.ts +1 -0
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +16 -7
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +3 -0
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +2 -4
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +7 -6
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +116 -78
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +0 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +3 -6
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +3 -3
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +13 -10
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs.js +137 -181
- package/core/core.cjs.js.map +1 -1
- package/core/index.d.ts +0 -1
- package/core/index.d.ts.map +1 -1
- package/core/index.js +2 -2
- package/core/index.js.map +1 -1
- package/core/types.d.ts +4 -1
- package/core/types.d.ts.map +1 -1
- package/core/types.js +1 -0
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.js +1 -0
- package/errors/errors.cjs.js +2 -0
- package/errors/errors.cjs.js.map +1 -1
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +3 -0
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +82 -57
- package/link/context/context.cjs.js +4 -0
- package/link/context/context.cjs.js.map +1 -1
- package/link/context/index.d.ts.map +1 -1
- package/link/context/index.js +4 -0
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.js +1 -1
- package/link/core/core.cjs.js +4 -2
- package/link/core/core.cjs.js.map +1 -1
- package/link/core/index.d.ts.map +1 -1
- package/link/core/index.js +3 -0
- package/link/core/index.js.map +1 -1
- package/link/core/types.js +1 -0
- package/link/http/checkFetcher.js +1 -1
- package/link/http/http.cjs.js +13 -3
- package/link/http/http.cjs.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +11 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs.js +2 -2
- package/link/persisted-queries/persisted-queries.cjs.js.map +1 -1
- package/link/utils/utils.cjs.js +1 -1
- package/link/utils/utils.cjs.js.map +1 -1
- package/link/utils/validateOperation.js +1 -1
- package/package.json +20 -20
- package/react/components/Mutation.d.ts +1 -1
- package/react/components/Query.js +1 -1
- package/react/components/Query.js.map +1 -1
- package/react/components/components.cjs.js +45 -31
- package/react/components/components.cjs.js.map +1 -1
- package/react/components/types.js +1 -0
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/context.cjs.js +22 -8
- package/react/context/context.cjs.js.map +1 -1
- package/react/data/OperationData.js +2 -2
- package/react/data/QueryData.d.ts +1 -2
- package/react/data/QueryData.d.ts.map +1 -1
- package/react/data/QueryData.js +65 -72
- package/react/data/QueryData.js.map +1 -1
- package/react/data/data.cjs.js +65 -71
- package/react/data/data.cjs.js.map +1 -1
- package/react/hoc/hoc-utils.d.ts +2 -1
- package/react/hoc/hoc-utils.d.ts.map +1 -1
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/hoc.cjs.js +35 -18
- package/react/hoc/hoc.cjs.js.map +1 -1
- package/react/hoc/mutation-hoc.d.ts.map +1 -1
- package/react/hoc/query-hoc.d.ts.map +1 -1
- package/react/hoc/subscription-hoc.d.ts.map +1 -1
- package/react/hoc/types.js +1 -0
- package/react/hoc/withApollo.js +1 -1
- package/react/hooks/hooks.cjs.js +56 -10
- package/react/hooks/hooks.cjs.js.map +1 -1
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +16 -6
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/utils/useAfterFastRefresh.d.ts +2 -0
- package/react/hooks/utils/useAfterFastRefresh.d.ts.map +1 -0
- package/react/hooks/utils/useAfterFastRefresh.js +18 -0
- package/react/hooks/utils/useAfterFastRefresh.js.map +1 -0
- package/react/hooks/utils/useBaseQuery.d.ts.map +1 -1
- package/react/hooks/utils/useBaseQuery.js +10 -3
- package/react/hooks/utils/useBaseQuery.js.map +1 -1
- package/react/index.d.ts +0 -1
- package/react/index.d.ts.map +1 -1
- package/react/index.js +3 -1
- package/react/index.js.map +1 -1
- package/react/parser/index.js +4 -4
- package/react/parser/parser.cjs.js +4 -4
- package/react/parser/parser.cjs.js.map +1 -1
- package/react/react.cjs.js +2 -2
- package/react/react.cjs.js.map +1 -1
- package/react/ssr/ssr.cjs.js +15 -1
- package/react/ssr/ssr.cjs.js.map +1 -1
- package/react/types/types.d.ts +9 -3
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js +1 -0
- package/react/types/types.js.map +1 -1
- package/testing/index.d.ts.map +1 -1
- package/testing/index.js +3 -0
- package/testing/index.js.map +1 -1
- package/testing/testing.cjs.js +68 -17
- package/testing/testing.cjs.js.map +1 -1
- package/utilities/common/canUse.d.ts +1 -0
- package/utilities/common/canUse.d.ts.map +1 -1
- package/utilities/common/canUse.js +1 -0
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/global.d.ts.map +1 -1
- package/utilities/common/mergeDeep.js +2 -2
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/common/stringifyForDisplay.d.ts +2 -0
- package/utilities/common/stringifyForDisplay.d.ts.map +1 -0
- package/utilities/common/stringifyForDisplay.js +8 -0
- package/utilities/common/stringifyForDisplay.js.map +1 -0
- package/utilities/globals/DEV.d.ts +3 -0
- package/utilities/globals/DEV.d.ts.map +1 -0
- package/utilities/globals/DEV.js +20 -0
- package/utilities/globals/DEV.js.map +1 -0
- package/utilities/globals/graphql.d.ts +1 -1
- package/utilities/globals/graphql.d.ts.map +1 -1
- package/utilities/globals/graphql.js +3 -3
- package/utilities/globals/graphql.js.map +1 -1
- package/utilities/globals/index.d.ts +4 -2
- package/utilities/globals/index.d.ts.map +1 -1
- package/utilities/globals/index.js +5 -4
- package/utilities/globals/index.js.map +1 -1
- package/utilities/graphql/directives.js +4 -4
- package/utilities/graphql/fragments.js +5 -5
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.js +2 -2
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +3 -1
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +5 -1
- package/utilities/index.js.map +1 -1
- package/utilities/package.json +3 -1
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +10 -11
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/testing/index.d.ts +1 -0
- package/utilities/testing/index.d.ts.map +1 -1
- package/utilities/testing/index.js +1 -0
- package/utilities/testing/index.js.map +1 -1
- package/utilities/testing/itAsync.d.ts +5 -8
- package/utilities/testing/itAsync.d.ts.map +1 -1
- package/utilities/testing/itAsync.js +6 -7
- package/utilities/testing/itAsync.js.map +1 -1
- package/utilities/testing/mocking/mockFetch.js +2 -2
- package/utilities/testing/mocking/mockFetch.js.map +1 -1
- package/utilities/testing/mocking/mockLink.d.ts.map +1 -1
- package/utilities/testing/mocking/mockLink.js +2 -8
- package/utilities/testing/mocking/mockLink.js.map +1 -1
- package/utilities/testing/mocking/mockWatchQuery.d.ts.map +1 -1
- package/utilities/testing/mocking/mockWatchQuery.js +2 -2
- package/utilities/testing/mocking/mockWatchQuery.js.map +1 -1
- package/utilities/testing/observableToPromise.js +2 -2
- package/utilities/testing/observableToPromise.js.map +1 -1
- package/utilities/testing/withConsoleSpy.d.ts +4 -0
- package/utilities/testing/withConsoleSpy.d.ts.map +1 -0
- package/utilities/testing/withConsoleSpy.js +39 -0
- package/utilities/testing/withConsoleSpy.js.map +1 -0
- package/utilities/types/IsStrictlyAny.js +1 -0
- package/utilities/utilities.cjs.js +56 -48
- package/utilities/utilities.cjs.js.map +1 -1
- package/version.js +1 -1
- package/core/Reobserver.d.ts +0 -18
- package/core/Reobserver.d.ts.map +0 -1
- package/core/Reobserver.js +0 -87
- package/core/Reobserver.js.map +0 -1
- package/utilities/globals/__DEV__.d.ts +0 -3
- package/utilities/globals/__DEV__.d.ts.map +0 -1
- package/utilities/globals/__DEV__.js +0 -32
- package/utilities/globals/__DEV__.js.map +0 -1
- package/utilities/globals/process.d.ts +0 -2
- package/utilities/globals/process.d.ts.map +0 -1
- package/utilities/globals/process.js +0 -31
- package/utilities/globals/process.js.map +0 -1
package/cache/cache.cjs.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var tsInvariant = require('ts-invariant');
|
|
5
6
|
var utilities = require('../utilities');
|
|
6
7
|
var tslib = require('tslib');
|
|
7
8
|
var optimism = require('optimism');
|
|
8
|
-
var tsInvariant = require('ts-invariant');
|
|
9
9
|
var equality = require('@wry/equality');
|
|
10
10
|
var trie = require('@wry/trie');
|
|
11
11
|
var context = require('@wry/context');
|
|
@@ -191,6 +191,10 @@ exports.EntityStore = (function () {
|
|
|
191
191
|
EntityStore.prototype.merge = function (older, newer) {
|
|
192
192
|
var _this = this;
|
|
193
193
|
var dataId;
|
|
194
|
+
if (utilities.isReference(older))
|
|
195
|
+
older = older.__ref;
|
|
196
|
+
if (utilities.isReference(newer))
|
|
197
|
+
newer = newer.__ref;
|
|
194
198
|
var existing = typeof older === "string"
|
|
195
199
|
? this.lookup(dataId = older)
|
|
196
200
|
: older;
|
|
@@ -199,7 +203,7 @@ exports.EntityStore = (function () {
|
|
|
199
203
|
: newer;
|
|
200
204
|
if (!incoming)
|
|
201
205
|
return;
|
|
202
|
-
__DEV__ ? tsInvariant.invariant(typeof dataId === "string", "store.merge expects a string ID") : tsInvariant.invariant(typeof dataId === "string",
|
|
206
|
+
__DEV__ ? tsInvariant.invariant(typeof dataId === "string", "store.merge expects a string ID") : tsInvariant.invariant(typeof dataId === "string", 2);
|
|
203
207
|
var merged = new utilities.DeepMerger(storeObjectReconciler).merge(existing, incoming);
|
|
204
208
|
this.data[dataId] = merged;
|
|
205
209
|
if (merged !== existing) {
|
|
@@ -258,8 +262,7 @@ exports.EntityStore = (function () {
|
|
|
258
262
|
: fields[storeFieldName] || fields[fieldName];
|
|
259
263
|
if (modify) {
|
|
260
264
|
var newValue = modify === delModifier ? DELETE :
|
|
261
|
-
modify(utilities.maybeDeepFreeze(fieldValue), tslib.__assign(tslib.__assign({}, sharedDetails_1), { fieldName: fieldName,
|
|
262
|
-
storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) }));
|
|
265
|
+
modify(utilities.maybeDeepFreeze(fieldValue), tslib.__assign(tslib.__assign({}, sharedDetails_1), { fieldName: fieldName, storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) }));
|
|
263
266
|
if (newValue === INVALIDATE) {
|
|
264
267
|
_this.group.dirty(dataId, storeFieldName);
|
|
265
268
|
}
|
|
@@ -401,15 +404,21 @@ exports.EntityStore = (function () {
|
|
|
401
404
|
EntityStore.prototype.findChildRefIds = function (dataId) {
|
|
402
405
|
if (!hasOwn.call(this.refs, dataId)) {
|
|
403
406
|
var found_1 = this.refs[dataId] = Object.create(null);
|
|
404
|
-
var
|
|
407
|
+
var root = this.data[dataId];
|
|
408
|
+
if (!root)
|
|
409
|
+
return found_1;
|
|
410
|
+
var workSet_1 = new Set([root]);
|
|
405
411
|
workSet_1.forEach(function (obj) {
|
|
406
412
|
if (utilities.isReference(obj)) {
|
|
407
413
|
found_1[obj.__ref] = true;
|
|
408
414
|
}
|
|
409
|
-
|
|
410
|
-
Object.
|
|
411
|
-
|
|
412
|
-
.
|
|
415
|
+
if (utilities.isNonNullObject(obj)) {
|
|
416
|
+
Object.keys(obj).forEach(function (key) {
|
|
417
|
+
var child = obj[key];
|
|
418
|
+
if (utilities.isNonNullObject(child)) {
|
|
419
|
+
workSet_1.add(child);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
413
422
|
}
|
|
414
423
|
});
|
|
415
424
|
}
|
|
@@ -426,9 +435,12 @@ var CacheGroup = (function () {
|
|
|
426
435
|
this.caching = caching;
|
|
427
436
|
this.parent = parent;
|
|
428
437
|
this.d = null;
|
|
429
|
-
this.
|
|
430
|
-
this.d = caching ? optimism.dep() : null;
|
|
438
|
+
this.resetCaching();
|
|
431
439
|
}
|
|
440
|
+
CacheGroup.prototype.resetCaching = function () {
|
|
441
|
+
this.d = this.caching ? optimism.dep() : null;
|
|
442
|
+
this.keyMaker = new trie.Trie(utilities.canUseWeakMap);
|
|
443
|
+
};
|
|
432
444
|
CacheGroup.prototype.depend = function (dataId, storeFieldName) {
|
|
433
445
|
if (this.d) {
|
|
434
446
|
this.d(makeDepKey(dataId, storeFieldName));
|
|
@@ -574,7 +586,7 @@ function shallowCopy(value) {
|
|
|
574
586
|
}
|
|
575
587
|
var ObjectCanon = (function () {
|
|
576
588
|
function ObjectCanon() {
|
|
577
|
-
this.known = new (utilities.
|
|
589
|
+
this.known = new (utilities.canUseWeakSet ? WeakSet : Set)();
|
|
578
590
|
this.pool = new trie.Trie(utilities.canUseWeakMap);
|
|
579
591
|
this.passes = new WeakMap();
|
|
580
592
|
this.keysByJSON = new Map();
|
|
@@ -657,6 +669,9 @@ var ObjectCanon = (function () {
|
|
|
657
669
|
}());
|
|
658
670
|
var canonicalStringify = Object.assign(function (value) {
|
|
659
671
|
if (utilities.isNonNullObject(value)) {
|
|
672
|
+
if (stringifyCanon === void 0) {
|
|
673
|
+
resetCanonicalStringify();
|
|
674
|
+
}
|
|
660
675
|
var canonical = stringifyCanon.admit(value);
|
|
661
676
|
var json = stringifyCache.get(canonical);
|
|
662
677
|
if (json === void 0) {
|
|
@@ -666,12 +681,14 @@ var canonicalStringify = Object.assign(function (value) {
|
|
|
666
681
|
}
|
|
667
682
|
return JSON.stringify(value);
|
|
668
683
|
}, {
|
|
669
|
-
reset:
|
|
670
|
-
stringifyCanon = new ObjectCanon;
|
|
671
|
-
},
|
|
684
|
+
reset: resetCanonicalStringify,
|
|
672
685
|
});
|
|
673
|
-
var stringifyCanon
|
|
674
|
-
var stringifyCache
|
|
686
|
+
var stringifyCanon;
|
|
687
|
+
var stringifyCache;
|
|
688
|
+
function resetCanonicalStringify() {
|
|
689
|
+
stringifyCanon = new ObjectCanon;
|
|
690
|
+
stringifyCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
|
|
691
|
+
}
|
|
675
692
|
|
|
676
693
|
function missingFromInvariant(err, context) {
|
|
677
694
|
return new MissingFieldError(err.message, context.path.slice(), context.query, context.variables);
|
|
@@ -687,9 +704,9 @@ function execSelectionSetKeyArgs(options) {
|
|
|
687
704
|
var StoreReader = (function () {
|
|
688
705
|
function StoreReader(config) {
|
|
689
706
|
var _this = this;
|
|
690
|
-
this.
|
|
691
|
-
this.knownResults = new WeakMap();
|
|
707
|
+
this.knownResults = new (utilities.canUseWeakMap ? WeakMap : Map)();
|
|
692
708
|
this.config = tslib.__assign(tslib.__assign({}, config), { addTypename: config.addTypename !== false });
|
|
709
|
+
this.canon = config.canon || new ObjectCanon;
|
|
693
710
|
this.executeSelectionSet = optimism.wrap(function (options) {
|
|
694
711
|
var _a;
|
|
695
712
|
var canonizeResults = options.context.canonizeResults;
|
|
@@ -726,6 +743,9 @@ var StoreReader = (function () {
|
|
|
726
743
|
}
|
|
727
744
|
});
|
|
728
745
|
}
|
|
746
|
+
StoreReader.prototype.resetCanon = function () {
|
|
747
|
+
this.canon = new ObjectCanon;
|
|
748
|
+
};
|
|
729
749
|
StoreReader.prototype.diffQueryAgainstStore = function (_a) {
|
|
730
750
|
var store = _a.store, query = _a.query, _b = _a.rootId, rootId = _b === void 0 ? 'ROOT_QUERY' : _b, variables = _a.variables, _c = _a.returnPartialData, returnPartialData = _c === void 0 ? true : _c, _d = _a.canonizeResults, canonizeResults = _d === void 0 ? true : _d;
|
|
731
751
|
var policies = this.config.cache.policies;
|
|
@@ -774,7 +794,7 @@ var StoreReader = (function () {
|
|
|
774
794
|
!context.store.has(objectOrReference.__ref)) {
|
|
775
795
|
return {
|
|
776
796
|
result: this.canon.empty,
|
|
777
|
-
missing: [missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new tsInvariant.InvariantError(
|
|
797
|
+
missing: [missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object") : new tsInvariant.InvariantError(6), context)],
|
|
778
798
|
};
|
|
779
799
|
}
|
|
780
800
|
var variables = context.variables, policies = context.policies, store = context.store;
|
|
@@ -813,7 +833,7 @@ var StoreReader = (function () {
|
|
|
813
833
|
if (!utilities.addTypenameToDocument.added(selection)) {
|
|
814
834
|
getMissing().push(missingFromInvariant(__DEV__ ? new tsInvariant.InvariantError("Can't find field '" + selection.name.value + "' on " + (utilities.isReference(objectOrReference)
|
|
815
835
|
? objectOrReference.__ref + " object"
|
|
816
|
-
: "object " + JSON.stringify(objectOrReference, null, 2))) : new tsInvariant.InvariantError(
|
|
836
|
+
: "object " + JSON.stringify(objectOrReference, null, 2))) : new tsInvariant.InvariantError(7), context));
|
|
817
837
|
}
|
|
818
838
|
}
|
|
819
839
|
else if (Array.isArray(fieldValue)) {
|
|
@@ -910,7 +930,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
910
930
|
var workSet_1 = new Set([fieldValue]);
|
|
911
931
|
workSet_1.forEach(function (value) {
|
|
912
932
|
if (utilities.isNonNullObject(value)) {
|
|
913
|
-
__DEV__ ? tsInvariant.invariant(!utilities.isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!utilities.isReference(value),
|
|
933
|
+
__DEV__ ? tsInvariant.invariant(!utilities.isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value) : tsInvariant.invariant(!utilities.isReference(value), 8);
|
|
914
934
|
Object.values(value).forEach(workSet_1.add, workSet_1);
|
|
915
935
|
}
|
|
916
936
|
});
|
|
@@ -939,6 +959,7 @@ var StoreWriter = (function () {
|
|
|
939
959
|
fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(query)),
|
|
940
960
|
overwrite: !!overwrite,
|
|
941
961
|
incomingById: new Map,
|
|
962
|
+
clientOnly: false,
|
|
942
963
|
};
|
|
943
964
|
var ref = this.processSelectionSet({
|
|
944
965
|
result: result || Object.create(null),
|
|
@@ -948,13 +969,17 @@ var StoreWriter = (function () {
|
|
|
948
969
|
context: context,
|
|
949
970
|
});
|
|
950
971
|
if (!utilities.isReference(ref)) {
|
|
951
|
-
throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(
|
|
972
|
+
throw __DEV__ ? new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result)) : new tsInvariant.InvariantError(9);
|
|
952
973
|
}
|
|
953
974
|
context.incomingById.forEach(function (_a, dataId) {
|
|
954
975
|
var fields = _a.fields, mergeTree = _a.mergeTree, selections = _a.selections;
|
|
955
976
|
var entityRef = utilities.makeReference(dataId);
|
|
956
977
|
if (mergeTree.map.size) {
|
|
957
|
-
|
|
978
|
+
var applied = _this.applyMerges(mergeTree, entityRef, fields, context);
|
|
979
|
+
if (utilities.isReference(applied)) {
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
fields = applied;
|
|
958
983
|
}
|
|
959
984
|
if (__DEV__ && !context.overwrite) {
|
|
960
985
|
var hasSelectionSet_1 = function (storeFieldName) {
|
|
@@ -1016,7 +1041,10 @@ var StoreWriter = (function () {
|
|
|
1016
1041
|
if (utilities.isField(selection)) {
|
|
1017
1042
|
var resultFieldKey = utilities.resultKeyNameFromField(selection);
|
|
1018
1043
|
var value = result[resultFieldKey];
|
|
1019
|
-
|
|
1044
|
+
var wasClientOnly = context.clientOnly;
|
|
1045
|
+
context.clientOnly = wasClientOnly || !!(selection.directives &&
|
|
1046
|
+
selection.directives.some(function (d) { return d.name.value === "client"; }));
|
|
1047
|
+
if (value !== void 0) {
|
|
1020
1048
|
var storeFieldName = policies.getStoreFieldName({
|
|
1021
1049
|
typename: typename,
|
|
1022
1050
|
fieldName: selection.name.value,
|
|
@@ -1048,10 +1076,11 @@ var StoreWriter = (function () {
|
|
|
1048
1076
|
_a[storeFieldName] = incomingValue,
|
|
1049
1077
|
_a));
|
|
1050
1078
|
}
|
|
1051
|
-
else if (
|
|
1052
|
-
!utilities.
|
|
1053
|
-
|
|
1079
|
+
else if (!context.clientOnly &&
|
|
1080
|
+
!utilities.addTypenameToDocument.added(selection)) {
|
|
1081
|
+
__DEV__ && tsInvariant.invariant.error(("Missing field '" + utilities.resultKeyNameFromField(selection) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
|
|
1054
1082
|
}
|
|
1083
|
+
context.clientOnly = wasClientOnly;
|
|
1055
1084
|
}
|
|
1056
1085
|
else {
|
|
1057
1086
|
var fragment = utilities.getFragmentFromSelection(selection, context.fragmentMap);
|
|
@@ -1437,7 +1466,7 @@ var Policies = (function () {
|
|
|
1437
1466
|
var rootId = "ROOT_" + which.toUpperCase();
|
|
1438
1467
|
var old = this.rootTypenamesById[rootId];
|
|
1439
1468
|
if (typename !== old) {
|
|
1440
|
-
__DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which,
|
|
1469
|
+
__DEV__ ? tsInvariant.invariant(!old || old === which, "Cannot change root " + which + " __typename more than once") : tsInvariant.invariant(!old || old === which, 3);
|
|
1441
1470
|
if (old)
|
|
1442
1471
|
delete this.rootIdsByTypename[old];
|
|
1443
1472
|
this.rootIdsByTypename[typename] = rootId;
|
|
@@ -1650,12 +1679,25 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
|
|
|
1650
1679
|
cache: policies.cache,
|
|
1651
1680
|
canRead: canRead,
|
|
1652
1681
|
readField: function (fieldNameOrOptions, from) {
|
|
1653
|
-
var options
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1682
|
+
var options;
|
|
1683
|
+
if (typeof fieldNameOrOptions === "string") {
|
|
1684
|
+
options = {
|
|
1685
|
+
fieldName: fieldNameOrOptions,
|
|
1686
|
+
from: arguments.length > 1 ? from : objectOrReference,
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
else if (utilities.isNonNullObject(fieldNameOrOptions)) {
|
|
1690
|
+
options = tslib.__assign({}, fieldNameOrOptions);
|
|
1691
|
+
if (!hasOwn.call(fieldNameOrOptions, "from")) {
|
|
1692
|
+
options.from = objectOrReference;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
else {
|
|
1696
|
+
__DEV__ && tsInvariant.invariant.warn("Unexpected readField arguments: " + utilities.stringifyForDisplay(Array.from(arguments)));
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
if (__DEV__ && options.from === void 0) {
|
|
1700
|
+
__DEV__ && tsInvariant.invariant.warn("Undefined 'from' passed to readField with arguments " + utilities.stringifyForDisplay(Array.from(arguments)));
|
|
1659
1701
|
}
|
|
1660
1702
|
if (void 0 === options.variables) {
|
|
1661
1703
|
options.variables = variables;
|
|
@@ -1668,7 +1710,7 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
|
|
|
1668
1710
|
function makeMergeObjectsFunction(store) {
|
|
1669
1711
|
return function mergeObjects(existing, incoming) {
|
|
1670
1712
|
if (Array.isArray(existing) || Array.isArray(incoming)) {
|
|
1671
|
-
throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(
|
|
1713
|
+
throw __DEV__ ? new tsInvariant.InvariantError("Cannot automatically merge arrays") : new tsInvariant.InvariantError(4);
|
|
1672
1714
|
}
|
|
1673
1715
|
if (utilities.isNonNullObject(existing) &&
|
|
1674
1716
|
utilities.isNonNullObject(incoming)) {
|
|
@@ -1765,7 +1807,7 @@ function computeKeyObject(response, specifier, strict, aliasMap) {
|
|
|
1765
1807
|
keyObj[prevKey = s] = response[responseName];
|
|
1766
1808
|
}
|
|
1767
1809
|
else {
|
|
1768
|
-
__DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict,
|
|
1810
|
+
__DEV__ ? tsInvariant.invariant(!strict, "Missing field '" + responseName + "' while computing key fields") : tsInvariant.invariant(!strict, 5);
|
|
1769
1811
|
prevKey = void 0;
|
|
1770
1812
|
}
|
|
1771
1813
|
}
|
|
@@ -1800,16 +1842,23 @@ var InMemoryCache = (function (_super) {
|
|
|
1800
1842
|
return _this;
|
|
1801
1843
|
}
|
|
1802
1844
|
InMemoryCache.prototype.init = function () {
|
|
1803
|
-
var _this = this;
|
|
1804
1845
|
var rootStore = this.data = new exports.EntityStore.Root({
|
|
1805
1846
|
policies: this.policies,
|
|
1806
1847
|
resultCaching: this.config.resultCaching,
|
|
1807
1848
|
});
|
|
1808
1849
|
this.optimisticData = rootStore.stump;
|
|
1850
|
+
this.resetResultCache();
|
|
1851
|
+
};
|
|
1852
|
+
InMemoryCache.prototype.resetResultCache = function (resetResultIdentities) {
|
|
1853
|
+
var _this = this;
|
|
1854
|
+
var previousReader = this.storeReader;
|
|
1809
1855
|
this.storeWriter = new StoreWriter(this, this.storeReader = new StoreReader({
|
|
1810
1856
|
cache: this,
|
|
1811
1857
|
addTypename: this.addTypename,
|
|
1812
1858
|
resultCacheMaxSize: this.config.resultCacheMaxSize,
|
|
1859
|
+
canon: resetResultIdentities
|
|
1860
|
+
? void 0
|
|
1861
|
+
: previousReader && previousReader.canon,
|
|
1813
1862
|
}));
|
|
1814
1863
|
this.maybeBroadcastWatch = optimism.wrap(function (c, options) {
|
|
1815
1864
|
return _this.broadcastWatch(c, options);
|
|
@@ -1823,8 +1872,13 @@ var InMemoryCache = (function (_super) {
|
|
|
1823
1872
|
}
|
|
1824
1873
|
}
|
|
1825
1874
|
});
|
|
1875
|
+
new Set([
|
|
1876
|
+
this.data.group,
|
|
1877
|
+
this.optimisticData.group,
|
|
1878
|
+
]).forEach(function (group) { return group.resetCaching(); });
|
|
1826
1879
|
};
|
|
1827
1880
|
InMemoryCache.prototype.restore = function (data) {
|
|
1881
|
+
this.init();
|
|
1828
1882
|
if (data)
|
|
1829
1883
|
this.data.replace(data);
|
|
1830
1884
|
return this;
|
|
@@ -1892,9 +1946,18 @@ var InMemoryCache = (function (_super) {
|
|
|
1892
1946
|
_this.maybeBroadcastWatch.forget(watch);
|
|
1893
1947
|
};
|
|
1894
1948
|
};
|
|
1895
|
-
InMemoryCache.prototype.gc = function () {
|
|
1949
|
+
InMemoryCache.prototype.gc = function (options) {
|
|
1896
1950
|
canonicalStringify.reset();
|
|
1897
|
-
|
|
1951
|
+
var ids = this.optimisticData.gc();
|
|
1952
|
+
if (options && !this.txCount) {
|
|
1953
|
+
if (options.resetResultCache) {
|
|
1954
|
+
this.resetResultCache(options.resetResultIdentities);
|
|
1955
|
+
}
|
|
1956
|
+
else if (options.resetResultIdentities) {
|
|
1957
|
+
this.storeReader.resetCanon();
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
return ids;
|
|
1898
1961
|
};
|
|
1899
1962
|
InMemoryCache.prototype.retain = function (rootId, optimistic) {
|
|
1900
1963
|
return (optimistic ? this.optimisticData : this.data).retain(rootId);
|
|
@@ -2037,7 +2100,8 @@ var InMemoryCache = (function (_super) {
|
|
|
2037
2100
|
return InMemoryCache;
|
|
2038
2101
|
}(ApolloCache));
|
|
2039
2102
|
|
|
2040
|
-
|
|
2103
|
+
__DEV__ ? tsInvariant.invariant("boolean" === typeof utilities.DEV, utilities.DEV) : tsInvariant.invariant("boolean" === typeof utilities.DEV, 1);
|
|
2104
|
+
|
|
2041
2105
|
exports.isReference = utilities.isReference;
|
|
2042
2106
|
exports.makeReference = utilities.makeReference;
|
|
2043
2107
|
exports.ApolloCache = ApolloCache;
|