@apollo/client 3.2.0-beta.9 → 3.2.2
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/LICENSE +1 -1
- package/apollo-client.cjs.js +161 -102
- package/apollo-client.cjs.js.map +1 -1
- package/apollo-client.cjs.min.js +1 -1
- package/cache/cache.cjs.js +117 -64
- package/cache/cache.cjs.js.map +1 -1
- package/cache/core/types/common.d.ts +3 -0
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +5 -1
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js +32 -19
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/helpers.d.ts +3 -1
- package/cache/inmemory/helpers.d.ts.map +1 -1
- package/cache/inmemory/helpers.js +19 -3
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +3 -2
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/policies.d.ts +6 -5
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +57 -26
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +1 -2
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +5 -14
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +2 -1
- package/cache/inmemory/types.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +4 -3
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.js +2 -2
- package/core/LocalState.js +1 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +9 -10
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +2 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +11 -7
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +17 -14
- package/core/QueryManager.js.map +1 -1
- package/core/Reobserver.js +1 -1
- package/core/core.cjs.js +39 -33
- package/core/core.cjs.js.map +1 -1
- package/core/types.d.ts +1 -1
- package/core/types.d.ts.map +1 -1
- package/core/watchQueryOptions.d.ts +1 -0
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/invariantErrorCodes.js +32 -28
- package/link/core/ApolloLink.js +1 -1
- package/link/core/core.cjs.js +1 -1
- package/link/core/core.cjs.js.map +1 -1
- package/link/http/checkFetcher.js +1 -1
- package/link/http/http.cjs.js +2 -2
- package/link/http/http.cjs.js.map +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.d.ts +30 -0
- package/link/persisted-queries/index.d.ts.map +1 -0
- package/link/persisted-queries/index.js +154 -0
- package/link/persisted-queries/index.js.map +1 -0
- package/link/persisted-queries/package.json +6 -0
- package/link/persisted-queries/persisted-queries.cjs.js +155 -0
- package/link/persisted-queries/persisted-queries.cjs.js.map +1 -0
- package/package.json +15 -10
- package/react/data/QueryData.js +2 -2
- package/react/data/QueryData.js.map +1 -1
- package/react/data/data.cjs.js +2 -2
- package/react/data/data.cjs.js.map +1 -1
- package/utilities/policies/pagination.d.ts +21 -12
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js +49 -37
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/utilities.cjs.js +48 -37
- package/utilities/utilities.cjs.js.map +1 -1
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2020 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/apollo-client.cjs.js
CHANGED
|
@@ -1188,7 +1188,7 @@ var ApolloLink = (function () {
|
|
|
1188
1188
|
return ApolloLink.concat(this, next);
|
|
1189
1189
|
};
|
|
1190
1190
|
ApolloLink.prototype.request = function (operation, forward) {
|
|
1191
|
-
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(
|
|
1191
|
+
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(21) : new tsInvariant.InvariantError('request is not implemented');
|
|
1192
1192
|
};
|
|
1193
1193
|
ApolloLink.prototype.onError = function (reason) {
|
|
1194
1194
|
throw reason;
|
|
@@ -1250,7 +1250,7 @@ var serializeFetchParameter = function (p, label) {
|
|
|
1250
1250
|
serialized = JSON.stringify(p);
|
|
1251
1251
|
}
|
|
1252
1252
|
catch (e) {
|
|
1253
|
-
var parseError = process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(
|
|
1253
|
+
var parseError = process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(23) : new tsInvariant.InvariantError("Network request failed. " + label + " is not serializable: " + e.message);
|
|
1254
1254
|
parseError.parseError = e;
|
|
1255
1255
|
throw parseError;
|
|
1256
1256
|
}
|
|
@@ -1300,7 +1300,7 @@ var selectHttpOptionsAndBody = function (operation, fallbackConfig) {
|
|
|
1300
1300
|
|
|
1301
1301
|
var checkFetcher = function (fetcher) {
|
|
1302
1302
|
if (!fetcher && typeof fetch === 'undefined') {
|
|
1303
|
-
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(
|
|
1303
|
+
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(22) : new tsInvariant.InvariantError("\n\"fetch\" has not been found globally and no fetcher has been configured. To fix this, install a fetch package (like https://www.npmjs.com/package/cross-fetch), instantiate the fetcher, and pass it into your HttpLink constructor. For example:\n\nimport fetch from 'cross-fetch';\nimport { ApolloClient, HttpLink } from '@apollo/client';\nconst client = new ApolloClient({\n link: new HttpLink({ uri: '/graphql', fetch })\n});\n ");
|
|
1304
1304
|
}
|
|
1305
1305
|
};
|
|
1306
1306
|
|
|
@@ -1606,7 +1606,7 @@ var Reobserver = (function () {
|
|
|
1606
1606
|
pollingInfo.interval === pollInterval) {
|
|
1607
1607
|
return;
|
|
1608
1608
|
}
|
|
1609
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(pollInterval,
|
|
1609
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(pollInterval, 20) : tsInvariant.invariant(pollInterval, 'Attempted to start a polling query without a polling interval.');
|
|
1610
1610
|
if (this.shouldFetch === false) {
|
|
1611
1611
|
return;
|
|
1612
1612
|
}
|
|
@@ -1655,7 +1655,7 @@ var ObservableQuery = (function (_super) {
|
|
|
1655
1655
|
}
|
|
1656
1656
|
},
|
|
1657
1657
|
error: function (error) {
|
|
1658
|
-
_this.updateLastResult(tslib.__assign(tslib.__assign({}, _this.lastResult), { errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false }));
|
|
1658
|
+
_this.updateLastResult(tslib.__assign(tslib.__assign({}, _this.lastResult), { error: error, errors: error.graphQLErrors, networkStatus: exports.NetworkStatus.error, loading: false }));
|
|
1659
1659
|
iterateObserversSafely(_this.observers, 'error', _this.lastError = error);
|
|
1660
1660
|
},
|
|
1661
1661
|
};
|
|
@@ -1696,13 +1696,15 @@ var ObservableQuery = (function (_super) {
|
|
|
1696
1696
|
};
|
|
1697
1697
|
ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
|
|
1698
1698
|
if (saveAsLastResult === void 0) { saveAsLastResult = true; }
|
|
1699
|
-
var
|
|
1700
|
-
var networkStatus = this.queryInfo.networkStatus ||
|
|
1701
|
-
|
|
1699
|
+
var lastResult = this.lastResult;
|
|
1700
|
+
var networkStatus = this.queryInfo.networkStatus ||
|
|
1701
|
+
(lastResult && lastResult.networkStatus) ||
|
|
1702
|
+
exports.NetworkStatus.ready;
|
|
1703
|
+
var result = tslib.__assign(tslib.__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
|
|
1702
1704
|
if (this.isTornDown) {
|
|
1703
1705
|
return result;
|
|
1704
1706
|
}
|
|
1705
|
-
var
|
|
1707
|
+
var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? 'cache-first' : _a;
|
|
1706
1708
|
if (fetchPolicy === 'no-cache' ||
|
|
1707
1709
|
fetchPolicy === 'network-only') {
|
|
1708
1710
|
delete result.partial;
|
|
@@ -1749,13 +1751,10 @@ var ObservableQuery = (function (_super) {
|
|
|
1749
1751
|
this.queryManager.resetErrors(this.queryId);
|
|
1750
1752
|
};
|
|
1751
1753
|
ObservableQuery.prototype.refetch = function (variables) {
|
|
1752
|
-
var fetchPolicy = this.options.fetchPolicy;
|
|
1753
|
-
if (fetchPolicy === 'cache-only') {
|
|
1754
|
-
return Promise.reject(process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(13) : new tsInvariant.InvariantError('cache-only fetchPolicy option should not be used together with query refetch.'));
|
|
1755
|
-
}
|
|
1756
1754
|
var reobserveOptions = {
|
|
1757
1755
|
pollInterval: 0,
|
|
1758
1756
|
};
|
|
1757
|
+
var fetchPolicy = this.options.fetchPolicy;
|
|
1759
1758
|
if (fetchPolicy !== 'no-cache' &&
|
|
1760
1759
|
fetchPolicy !== 'cache-and-network') {
|
|
1761
1760
|
reobserveOptions.fetchPolicy = 'network-only';
|
|
@@ -2052,11 +2051,27 @@ function getTypenameFromStoreObject(store, objectOrReference) {
|
|
|
2052
2051
|
? store.get(objectOrReference.__ref, "__typename")
|
|
2053
2052
|
: objectOrReference && objectOrReference.__typename;
|
|
2054
2053
|
}
|
|
2055
|
-
var
|
|
2054
|
+
var TypeOrFieldNameRegExp = /^[_a-z][_0-9a-z]*/i;
|
|
2056
2055
|
function fieldNameFromStoreName(storeFieldName) {
|
|
2057
|
-
var match = storeFieldName.match(
|
|
2056
|
+
var match = storeFieldName.match(TypeOrFieldNameRegExp);
|
|
2058
2057
|
return match ? match[0] : storeFieldName;
|
|
2059
2058
|
}
|
|
2059
|
+
function selectionSetMatchesResult(selectionSet, result, variables) {
|
|
2060
|
+
if (result && typeof result === "object") {
|
|
2061
|
+
return Array.isArray(result)
|
|
2062
|
+
? result.every(function (item) { return selectionSetMatchesResult(selectionSet, item, variables); })
|
|
2063
|
+
: selectionSet.selections.every(function (field) {
|
|
2064
|
+
if (isField(field) && shouldInclude(field, variables)) {
|
|
2065
|
+
var key = resultKeyNameFromField(field);
|
|
2066
|
+
return hasOwn.call(result, key) &&
|
|
2067
|
+
(!field.selectionSet ||
|
|
2068
|
+
selectionSetMatchesResult(field.selectionSet, result[key], variables));
|
|
2069
|
+
}
|
|
2070
|
+
return true;
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
return false;
|
|
2074
|
+
}
|
|
2060
2075
|
function storeValueIsStoreObject(value) {
|
|
2061
2076
|
return value !== null &&
|
|
2062
2077
|
typeof value === "object" &&
|
|
@@ -2088,6 +2103,7 @@ var reconcileProcessedFields = function (existingObject, incomingObject, propert
|
|
|
2088
2103
|
|
|
2089
2104
|
var DELETE = Object.create(null);
|
|
2090
2105
|
var delModifier = function () { return DELETE; };
|
|
2106
|
+
var INVALIDATE = Object.create(null);
|
|
2091
2107
|
var EntityStore = (function () {
|
|
2092
2108
|
function EntityStore(policies, group) {
|
|
2093
2109
|
var _this = this;
|
|
@@ -2179,10 +2195,17 @@ var EntityStore = (function () {
|
|
|
2179
2195
|
var changedFields_1 = Object.create(null);
|
|
2180
2196
|
var needToMerge_1 = false;
|
|
2181
2197
|
var allDeleted_1 = true;
|
|
2182
|
-
var
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2198
|
+
var sharedDetails_1 = {
|
|
2199
|
+
DELETE: DELETE,
|
|
2200
|
+
INVALIDATE: INVALIDATE,
|
|
2201
|
+
isReference: isReference,
|
|
2202
|
+
toReference: this.toReference,
|
|
2203
|
+
canRead: this.canRead,
|
|
2204
|
+
readField: function (fieldNameOrOptions, from) { return _this.policies.readField(typeof fieldNameOrOptions === "string" ? {
|
|
2205
|
+
fieldName: fieldNameOrOptions,
|
|
2206
|
+
from: from || makeReference(dataId),
|
|
2207
|
+
} : fieldNameOrOptions, { store: _this }); },
|
|
2208
|
+
};
|
|
2186
2209
|
Object.keys(storeObject).forEach(function (storeFieldName) {
|
|
2187
2210
|
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
2188
2211
|
var fieldValue = storeObject[storeFieldName];
|
|
@@ -2193,21 +2216,19 @@ var EntityStore = (function () {
|
|
|
2193
2216
|
: fields[storeFieldName] || fields[fieldName];
|
|
2194
2217
|
if (modify) {
|
|
2195
2218
|
var newValue = modify === delModifier ? DELETE :
|
|
2196
|
-
modify(maybeDeepFreeze(fieldValue), {
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
needToMerge_1 = true;
|
|
2210
|
-
fieldValue = newValue;
|
|
2219
|
+
modify(maybeDeepFreeze(fieldValue), tslib.__assign(tslib.__assign({}, sharedDetails_1), { fieldName: fieldName,
|
|
2220
|
+
storeFieldName: storeFieldName, storage: _this.getStorage(dataId, storeFieldName) }));
|
|
2221
|
+
if (newValue === INVALIDATE) {
|
|
2222
|
+
_this.group.dirty(dataId, storeFieldName);
|
|
2223
|
+
}
|
|
2224
|
+
else {
|
|
2225
|
+
if (newValue === DELETE)
|
|
2226
|
+
newValue = void 0;
|
|
2227
|
+
if (newValue !== fieldValue) {
|
|
2228
|
+
changedFields_1[storeFieldName] = newValue;
|
|
2229
|
+
needToMerge_1 = true;
|
|
2230
|
+
fieldValue = newValue;
|
|
2231
|
+
}
|
|
2211
2232
|
}
|
|
2212
2233
|
}
|
|
2213
2234
|
if (fieldValue !== void 0) {
|
|
@@ -2369,6 +2390,7 @@ function makeDepKey(dataId, storeFieldName) {
|
|
|
2369
2390
|
function Root(_a) {
|
|
2370
2391
|
var policies = _a.policies, _b = _a.resultCaching, resultCaching = _b === void 0 ? true : _b, seed = _a.seed;
|
|
2371
2392
|
var _this = _super.call(this, policies, new CacheGroup(resultCaching)) || this;
|
|
2393
|
+
_this.storageTrie = new optimism.KeyTrie(canUseWeakMap);
|
|
2372
2394
|
_this.sharedLayerGroup = new CacheGroup(resultCaching);
|
|
2373
2395
|
if (seed)
|
|
2374
2396
|
_this.replace(seed);
|
|
@@ -2380,6 +2402,9 @@ function makeDepKey(dataId, storeFieldName) {
|
|
|
2380
2402
|
Root.prototype.removeLayer = function () {
|
|
2381
2403
|
return this;
|
|
2382
2404
|
};
|
|
2405
|
+
Root.prototype.getStorage = function (idOrObj, storeFieldName) {
|
|
2406
|
+
return this.storageTrie.lookup(idOrObj, storeFieldName);
|
|
2407
|
+
};
|
|
2383
2408
|
return Root;
|
|
2384
2409
|
}(EntityStore));
|
|
2385
2410
|
EntityStore.Root = Root;
|
|
@@ -2422,6 +2447,9 @@ var Layer = (function (_super) {
|
|
|
2422
2447
|
var fromParent = this.parent.findChildRefIds(dataId);
|
|
2423
2448
|
return hasOwn.call(this.data, dataId) ? tslib.__assign(tslib.__assign({}, fromParent), _super.prototype.findChildRefIds.call(this, dataId)) : fromParent;
|
|
2424
2449
|
};
|
|
2450
|
+
Layer.prototype.getStorage = function (idOrObj, storeFieldName) {
|
|
2451
|
+
return this.parent.getStorage(idOrObj, storeFieldName);
|
|
2452
|
+
};
|
|
2425
2453
|
return Layer;
|
|
2426
2454
|
}(EntityStore));
|
|
2427
2455
|
function storeObjectReconciler(existingObject, incomingObject, property) {
|
|
@@ -2467,9 +2495,6 @@ var StoreReader = (function () {
|
|
|
2467
2495
|
});
|
|
2468
2496
|
this.config = tslib.__assign({ addTypename: true }, config);
|
|
2469
2497
|
}
|
|
2470
|
-
StoreReader.prototype.readQueryFromStore = function (options) {
|
|
2471
|
-
return this.diffQueryAgainstStore(tslib.__assign(tslib.__assign({}, options), { returnPartialData: false })).result;
|
|
2472
|
-
};
|
|
2473
2498
|
StoreReader.prototype.diffQueryAgainstStore = function (_a) {
|
|
2474
2499
|
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;
|
|
2475
2500
|
var policies = this.config.cache.policies;
|
|
@@ -2519,7 +2544,7 @@ var StoreReader = (function () {
|
|
|
2519
2544
|
missing: [missingFromInvariant(process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(4) : new tsInvariant.InvariantError("Dangling reference to missing " + objectOrReference.__ref + " object"), context)],
|
|
2520
2545
|
};
|
|
2521
2546
|
}
|
|
2522
|
-
var
|
|
2547
|
+
var variables = context.variables, policies = context.policies, store = context.store;
|
|
2523
2548
|
var objectsToMerge = [];
|
|
2524
2549
|
var finalResult = { result: null };
|
|
2525
2550
|
var typename = store.getFieldValue(objectOrReference, "__typename");
|
|
@@ -2588,14 +2613,8 @@ var StoreReader = (function () {
|
|
|
2588
2613
|
tsInvariant.invariant(context.path.pop() === resultName);
|
|
2589
2614
|
}
|
|
2590
2615
|
else {
|
|
2591
|
-
var fragment =
|
|
2592
|
-
if (
|
|
2593
|
-
fragment = selection;
|
|
2594
|
-
}
|
|
2595
|
-
else {
|
|
2596
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragment = fragmentMap[selection.name.value], 6) : tsInvariant.invariant(fragment = fragmentMap[selection.name.value], "No fragment named " + selection.name.value);
|
|
2597
|
-
}
|
|
2598
|
-
if (policies.fragmentMatches(fragment, typename)) {
|
|
2616
|
+
var fragment = getFragmentFromSelection(selection, context.fragmentMap);
|
|
2617
|
+
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
2599
2618
|
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
2600
2619
|
}
|
|
2601
2620
|
}
|
|
@@ -2659,7 +2678,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
2659
2678
|
var workSet_1 = new Set([fieldValue]);
|
|
2660
2679
|
workSet_1.forEach(function (value) {
|
|
2661
2680
|
if (value && typeof value === "object") {
|
|
2662
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!isReference(value),
|
|
2681
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!isReference(value), 6) : tsInvariant.invariant(!isReference(value), "Missing selection set for object of type " + getTypenameFromStoreObject(store, value) + " returned for query field " + field.name.value);
|
|
2663
2682
|
Object.values(value).forEach(workSet_1.add, workSet_1);
|
|
2664
2683
|
}
|
|
2665
2684
|
});
|
|
@@ -2692,7 +2711,7 @@ var StoreWriter = (function () {
|
|
|
2692
2711
|
},
|
|
2693
2712
|
});
|
|
2694
2713
|
if (!isReference(ref)) {
|
|
2695
|
-
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(
|
|
2714
|
+
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(7) : new tsInvariant.InvariantError("Could not identify object " + JSON.stringify(result));
|
|
2696
2715
|
}
|
|
2697
2716
|
store.retain(ref.__ref);
|
|
2698
2717
|
return ref;
|
|
@@ -2755,12 +2774,13 @@ var StoreWriter = (function () {
|
|
|
2755
2774
|
}
|
|
2756
2775
|
else if (policies.usingPossibleTypes &&
|
|
2757
2776
|
!hasDirectives(["defer", "client"], selection)) {
|
|
2758
|
-
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(
|
|
2777
|
+
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(8) : new tsInvariant.InvariantError("Missing field '" + resultFieldKey + "' in " + JSON.stringify(result, null, 2).substring(0, 100));
|
|
2759
2778
|
}
|
|
2760
2779
|
}
|
|
2761
2780
|
else {
|
|
2762
2781
|
var fragment = getFragmentFromSelection(selection, context.fragmentMap);
|
|
2763
|
-
if (fragment &&
|
|
2782
|
+
if (fragment &&
|
|
2783
|
+
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
2764
2784
|
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
2765
2785
|
}
|
|
2766
2786
|
}
|
|
@@ -2917,10 +2937,11 @@ var Policies = (function () {
|
|
|
2917
2937
|
function Policies(config) {
|
|
2918
2938
|
this.config = config;
|
|
2919
2939
|
this.typePolicies = Object.create(null);
|
|
2940
|
+
this.supertypeMap = new Map();
|
|
2941
|
+
this.fuzzySubtypes = new Map();
|
|
2920
2942
|
this.rootIdsByTypename = Object.create(null);
|
|
2921
2943
|
this.rootTypenamesById = Object.create(null);
|
|
2922
2944
|
this.usingPossibleTypes = false;
|
|
2923
|
-
this.storageTrie = new optimism.KeyTrie(true);
|
|
2924
2945
|
this.config = tslib.__assign({ dataIdFromObject: defaultDataIdFromObject }, config);
|
|
2925
2946
|
this.cache = this.config.cache;
|
|
2926
2947
|
this.setRootTypename("Query");
|
|
@@ -3023,8 +3044,14 @@ var Policies = (function () {
|
|
|
3023
3044
|
var _this = this;
|
|
3024
3045
|
this.usingPossibleTypes = true;
|
|
3025
3046
|
Object.keys(possibleTypes).forEach(function (supertype) {
|
|
3026
|
-
|
|
3027
|
-
possibleTypes[supertype].forEach(
|
|
3047
|
+
_this.getSupertypeSet(supertype, true);
|
|
3048
|
+
possibleTypes[supertype].forEach(function (subtype) {
|
|
3049
|
+
_this.getSupertypeSet(subtype, true).add(supertype);
|
|
3050
|
+
var match = subtype.match(TypeOrFieldNameRegExp);
|
|
3051
|
+
if (!match || match[0] !== subtype) {
|
|
3052
|
+
_this.fuzzySubtypes.set(subtype, new RegExp(subtype));
|
|
3053
|
+
}
|
|
3054
|
+
});
|
|
3028
3055
|
});
|
|
3029
3056
|
};
|
|
3030
3057
|
Policies.prototype.getTypePolicy = function (typename, createIfMissing) {
|
|
@@ -3032,12 +3059,6 @@ var Policies = (function () {
|
|
|
3032
3059
|
return this.typePolicies[typename] || (createIfMissing && (this.typePolicies[typename] = Object.create(null)));
|
|
3033
3060
|
}
|
|
3034
3061
|
};
|
|
3035
|
-
Policies.prototype.getSubtypeSet = function (supertype, createIfMissing) {
|
|
3036
|
-
var policy = this.getTypePolicy(supertype, createIfMissing);
|
|
3037
|
-
if (policy) {
|
|
3038
|
-
return policy.subtypes || (createIfMissing ? policy.subtypes = new Set() : void 0);
|
|
3039
|
-
}
|
|
3040
|
-
};
|
|
3041
3062
|
Policies.prototype.getFieldPolicy = function (typename, fieldName, createIfMissing) {
|
|
3042
3063
|
var typePolicy = this.getTypePolicy(typename, createIfMissing);
|
|
3043
3064
|
if (typePolicy) {
|
|
@@ -3047,7 +3068,14 @@ var Policies = (function () {
|
|
|
3047
3068
|
}
|
|
3048
3069
|
}
|
|
3049
3070
|
};
|
|
3050
|
-
Policies.prototype.
|
|
3071
|
+
Policies.prototype.getSupertypeSet = function (subtype, createIfMissing) {
|
|
3072
|
+
var supertypeSet = this.supertypeMap.get(subtype);
|
|
3073
|
+
if (!supertypeSet && createIfMissing) {
|
|
3074
|
+
this.supertypeMap.set(subtype, supertypeSet = new Set());
|
|
3075
|
+
}
|
|
3076
|
+
return supertypeSet;
|
|
3077
|
+
};
|
|
3078
|
+
Policies.prototype.fragmentMatches = function (fragment, typename, result, variables) {
|
|
3051
3079
|
var _this = this;
|
|
3052
3080
|
if (!fragment.typeCondition)
|
|
3053
3081
|
return true;
|
|
@@ -3056,17 +3084,41 @@ var Policies = (function () {
|
|
|
3056
3084
|
var supertype = fragment.typeCondition.name.value;
|
|
3057
3085
|
if (typename === supertype)
|
|
3058
3086
|
return true;
|
|
3059
|
-
if (this.usingPossibleTypes
|
|
3060
|
-
|
|
3087
|
+
if (this.usingPossibleTypes &&
|
|
3088
|
+
this.supertypeMap.has(supertype)) {
|
|
3089
|
+
var typenameSupertypeSet = this.getSupertypeSet(typename, true);
|
|
3090
|
+
var workQueue_1 = [typenameSupertypeSet];
|
|
3091
|
+
var maybeEnqueue_1 = function (subtype) {
|
|
3092
|
+
var supertypeSet = _this.getSupertypeSet(subtype, false);
|
|
3093
|
+
if (supertypeSet &&
|
|
3094
|
+
supertypeSet.size &&
|
|
3095
|
+
workQueue_1.indexOf(supertypeSet) < 0) {
|
|
3096
|
+
workQueue_1.push(supertypeSet);
|
|
3097
|
+
}
|
|
3098
|
+
};
|
|
3099
|
+
var needToCheckFuzzySubtypes = !!(result && this.fuzzySubtypes.size);
|
|
3100
|
+
var checkingFuzzySubtypes = false;
|
|
3061
3101
|
for (var i = 0; i < workQueue_1.length; ++i) {
|
|
3062
|
-
var
|
|
3063
|
-
if (
|
|
3064
|
-
if (
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3102
|
+
var supertypeSet = workQueue_1[i];
|
|
3103
|
+
if (supertypeSet.has(supertype)) {
|
|
3104
|
+
if (!typenameSupertypeSet.has(supertype)) {
|
|
3105
|
+
if (checkingFuzzySubtypes) {
|
|
3106
|
+
process.env.NODE_ENV === "production" || tsInvariant.invariant.warn("Inferring subtype " + typename + " of supertype " + supertype);
|
|
3107
|
+
}
|
|
3108
|
+
typenameSupertypeSet.add(supertype);
|
|
3109
|
+
}
|
|
3110
|
+
return true;
|
|
3111
|
+
}
|
|
3112
|
+
supertypeSet.forEach(maybeEnqueue_1);
|
|
3113
|
+
if (needToCheckFuzzySubtypes &&
|
|
3114
|
+
i === workQueue_1.length - 1 &&
|
|
3115
|
+
selectionSetMatchesResult(fragment.selectionSet, result, variables)) {
|
|
3116
|
+
needToCheckFuzzySubtypes = false;
|
|
3117
|
+
checkingFuzzySubtypes = true;
|
|
3118
|
+
this.fuzzySubtypes.forEach(function (regExp, fuzzyString) {
|
|
3119
|
+
var match = typename.match(regExp);
|
|
3120
|
+
if (match && match[0] === typename) {
|
|
3121
|
+
maybeEnqueue_1(fuzzyString);
|
|
3070
3122
|
}
|
|
3071
3123
|
});
|
|
3072
3124
|
}
|
|
@@ -3125,7 +3177,7 @@ var Policies = (function () {
|
|
|
3125
3177
|
var policy = this.getFieldPolicy(options.typename, fieldName, false);
|
|
3126
3178
|
var read = policy && policy.read;
|
|
3127
3179
|
if (read) {
|
|
3128
|
-
var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context,
|
|
3180
|
+
var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context, context.store.getStorage(isReference(objectOrReference)
|
|
3129
3181
|
? objectOrReference.__ref
|
|
3130
3182
|
: objectOrReference, storeFieldName));
|
|
3131
3183
|
return cacheSlot.withValue(this.cache, read, [existing, readOptions]);
|
|
@@ -3137,16 +3189,15 @@ var Policies = (function () {
|
|
|
3137
3189
|
return !!(policy && policy.merge);
|
|
3138
3190
|
};
|
|
3139
3191
|
Policies.prototype.applyMerges = function (existing, incoming, context, storageKeys) {
|
|
3192
|
+
var _a;
|
|
3140
3193
|
var _this = this;
|
|
3141
3194
|
if (isFieldValueToBeMerged(incoming)) {
|
|
3142
3195
|
var field = incoming.__field;
|
|
3143
3196
|
var fieldName = field.name.value;
|
|
3144
3197
|
var merge = this.getFieldPolicy(incoming.__typename, fieldName, false).merge;
|
|
3145
|
-
var storage = storageKeys
|
|
3146
|
-
? this.storageTrie.lookupArray(storageKeys)
|
|
3147
|
-
: null;
|
|
3148
3198
|
incoming = merge(existing, incoming.__value, makeFieldFunctionOptions(this, void 0, { typename: incoming.__typename, fieldName: fieldName,
|
|
3149
|
-
field: field, variables: context.variables }, context,
|
|
3199
|
+
field: field, variables: context.variables }, context, storageKeys
|
|
3200
|
+
? (_a = context.store).getStorage.apply(_a, storageKeys) : Object.create(null)));
|
|
3150
3201
|
}
|
|
3151
3202
|
if (Array.isArray(incoming)) {
|
|
3152
3203
|
return incoming.map(function (item) { return _this.applyMerges(void 0, item, context); });
|
|
@@ -3356,13 +3407,14 @@ var InMemoryCache = (function (_super) {
|
|
|
3356
3407
|
if (typeof options.rootId === 'string' && !store.has(options.rootId)) {
|
|
3357
3408
|
return null;
|
|
3358
3409
|
}
|
|
3359
|
-
return this.storeReader.
|
|
3410
|
+
return this.storeReader.diffQueryAgainstStore({
|
|
3360
3411
|
store: store,
|
|
3361
3412
|
query: options.query,
|
|
3362
3413
|
variables: options.variables,
|
|
3363
3414
|
rootId: options.rootId,
|
|
3364
3415
|
config: this.config,
|
|
3365
|
-
|
|
3416
|
+
returnPartialData: false,
|
|
3417
|
+
}).result || null;
|
|
3366
3418
|
};
|
|
3367
3419
|
InMemoryCache.prototype.write = function (options) {
|
|
3368
3420
|
try {
|
|
@@ -3696,7 +3748,7 @@ var LocalState = (function () {
|
|
|
3696
3748
|
}
|
|
3697
3749
|
else {
|
|
3698
3750
|
fragment = fragmentMap[selection.name.value];
|
|
3699
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragment,
|
|
3751
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(fragment, 11) : tsInvariant.invariant(fragment, "No fragment named " + selection.name.value);
|
|
3700
3752
|
}
|
|
3701
3753
|
if (fragment && fragment.typeCondition) {
|
|
3702
3754
|
typeCondition = fragment.typeCondition.name.value;
|
|
@@ -3953,13 +4005,7 @@ var QueryInfo = (function () {
|
|
|
3953
4005
|
this.diff = { result: result.data, complete: true };
|
|
3954
4006
|
}
|
|
3955
4007
|
else if (allowCacheWrite) {
|
|
3956
|
-
|
|
3957
|
-
options.errorPolicy === 'all';
|
|
3958
|
-
var writeWithErrors = !graphQLResultHasError(result);
|
|
3959
|
-
if (!writeWithErrors && ignoreErrors && result.data) {
|
|
3960
|
-
writeWithErrors = true;
|
|
3961
|
-
}
|
|
3962
|
-
if (writeWithErrors) {
|
|
4008
|
+
if (shouldWriteResult(result, options.errorPolicy)) {
|
|
3963
4009
|
this.cache.performTransaction(function (cache) {
|
|
3964
4010
|
if (_this.shouldWrite(result, options.variables)) {
|
|
3965
4011
|
cache.writeQuery({
|
|
@@ -4014,6 +4060,16 @@ var QueryInfo = (function () {
|
|
|
4014
4060
|
};
|
|
4015
4061
|
return QueryInfo;
|
|
4016
4062
|
}());
|
|
4063
|
+
function shouldWriteResult(result, errorPolicy) {
|
|
4064
|
+
if (errorPolicy === void 0) { errorPolicy = "none"; }
|
|
4065
|
+
var ignoreErrors = errorPolicy === "ignore" ||
|
|
4066
|
+
errorPolicy === "all";
|
|
4067
|
+
var writeWithErrors = !graphQLResultHasError(result);
|
|
4068
|
+
if (!writeWithErrors && ignoreErrors && result.data) {
|
|
4069
|
+
writeWithErrors = true;
|
|
4070
|
+
}
|
|
4071
|
+
return writeWithErrors;
|
|
4072
|
+
}
|
|
4017
4073
|
|
|
4018
4074
|
var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
4019
4075
|
var QueryManager = (function () {
|
|
@@ -4042,7 +4098,7 @@ var QueryManager = (function () {
|
|
|
4042
4098
|
this.queries.forEach(function (_info, queryId) {
|
|
4043
4099
|
_this.stopQueryNoBroadcast(queryId);
|
|
4044
4100
|
});
|
|
4045
|
-
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(
|
|
4101
|
+
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(12) : new tsInvariant.InvariantError('QueryManager stopped while query was in flight'));
|
|
4046
4102
|
};
|
|
4047
4103
|
QueryManager.prototype.cancelPendingFetches = function (error) {
|
|
4048
4104
|
this.fetchCancelFns.forEach(function (cancel) { return cancel(error); });
|
|
@@ -4056,8 +4112,8 @@ var QueryManager = (function () {
|
|
|
4056
4112
|
return tslib.__generator(this, function (_f) {
|
|
4057
4113
|
switch (_f.label) {
|
|
4058
4114
|
case 0:
|
|
4059
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(mutation,
|
|
4060
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache',
|
|
4115
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(mutation, 13) : tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.');
|
|
4116
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', 14) : tsInvariant.invariant(!fetchPolicy || fetchPolicy === 'no-cache', "Mutations only support a 'no-cache' fetchPolicy. If you don't want to disable the cache, remove your fetchPolicy setting to proceed with the default mutation behavior.");
|
|
4061
4117
|
mutationId = this.generateMutationId();
|
|
4062
4118
|
mutation = this.transform(mutation).document;
|
|
4063
4119
|
variables = this.getVariables(mutation, variables);
|
|
@@ -4098,6 +4154,7 @@ var QueryManager = (function () {
|
|
|
4098
4154
|
result: { data: optimistic_1 },
|
|
4099
4155
|
document: mutation,
|
|
4100
4156
|
variables: variables,
|
|
4157
|
+
errorPolicy: errorPolicy,
|
|
4101
4158
|
queryUpdatersById: generateUpdateQueriesInfo(),
|
|
4102
4159
|
update: updateWithProxyFn,
|
|
4103
4160
|
}, cache);
|
|
@@ -4128,6 +4185,7 @@ var QueryManager = (function () {
|
|
|
4128
4185
|
result: result,
|
|
4129
4186
|
document: mutation,
|
|
4130
4187
|
variables: variables,
|
|
4188
|
+
errorPolicy: errorPolicy,
|
|
4131
4189
|
queryUpdatersById: generateUpdateQueriesInfo(),
|
|
4132
4190
|
update: updateWithProxyFn,
|
|
4133
4191
|
}, self.cache);
|
|
@@ -4279,11 +4337,11 @@ var QueryManager = (function () {
|
|
|
4279
4337
|
};
|
|
4280
4338
|
QueryManager.prototype.query = function (options) {
|
|
4281
4339
|
var _this = this;
|
|
4282
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(options.query,
|
|
4340
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(options.query, 15) : tsInvariant.invariant(options.query, 'query option is required. You must specify your GraphQL document ' +
|
|
4283
4341
|
'in the query option.');
|
|
4284
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(options.query.kind === 'Document',
|
|
4285
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!options.returnPartialData,
|
|
4286
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!options.pollInterval,
|
|
4342
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(options.query.kind === 'Document', 16) : tsInvariant.invariant(options.query.kind === 'Document', 'You must wrap the query string in a "gql" tag.');
|
|
4343
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!options.returnPartialData, 17) : tsInvariant.invariant(!options.returnPartialData, 'returnPartialData option only supported on watchQuery.');
|
|
4344
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(!options.pollInterval, 18) : tsInvariant.invariant(!options.pollInterval, 'pollInterval option only supported on watchQuery.');
|
|
4287
4345
|
var queryId = this.generateQueryId();
|
|
4288
4346
|
return this.fetchQuery(queryId, options).finally(function () { return _this.stopQuery(queryId); });
|
|
4289
4347
|
};
|
|
@@ -4306,7 +4364,7 @@ var QueryManager = (function () {
|
|
|
4306
4364
|
queryInfo.stop();
|
|
4307
4365
|
};
|
|
4308
4366
|
QueryManager.prototype.clearStore = function () {
|
|
4309
|
-
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(
|
|
4367
|
+
this.cancelPendingFetches(process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(19) : new tsInvariant.InvariantError('Store reset while query was in flight (not completed in link chain)'));
|
|
4310
4368
|
this.queries.forEach(function (queryInfo) {
|
|
4311
4369
|
if (queryInfo.observableQuery) {
|
|
4312
4370
|
queryInfo.networkStatus = exports.NetworkStatus.loading;
|
|
@@ -4348,13 +4406,13 @@ var QueryManager = (function () {
|
|
|
4348
4406
|
};
|
|
4349
4407
|
QueryManager.prototype.startGraphQLSubscription = function (_a) {
|
|
4350
4408
|
var _this = this;
|
|
4351
|
-
var query = _a.query, fetchPolicy = _a.fetchPolicy, variables = _a.variables, _b = _a.context, context = _b === void 0 ? {} : _b;
|
|
4409
|
+
var query = _a.query, fetchPolicy = _a.fetchPolicy, errorPolicy = _a.errorPolicy, variables = _a.variables, _b = _a.context, context = _b === void 0 ? {} : _b;
|
|
4352
4410
|
query = this.transform(query).document;
|
|
4353
4411
|
variables = this.getVariables(query, variables);
|
|
4354
4412
|
var makeObservable = function (variables) {
|
|
4355
4413
|
return _this.getObservableFromLink(query, context, variables, false).map(function (result) {
|
|
4356
|
-
if (
|
|
4357
|
-
if (
|
|
4414
|
+
if (fetchPolicy !== 'no-cache') {
|
|
4415
|
+
if (shouldWriteResult(result, errorPolicy)) {
|
|
4358
4416
|
_this.cache.write({
|
|
4359
4417
|
query: query,
|
|
4360
4418
|
result: result.data,
|
|
@@ -4560,7 +4618,8 @@ var QueryManager = (function () {
|
|
|
4560
4618
|
var data = diff.result;
|
|
4561
4619
|
if (process.env.NODE_ENV !== 'production' &&
|
|
4562
4620
|
isNonEmptyArray(diff.missing) &&
|
|
4563
|
-
!equality.equal(data, {})
|
|
4621
|
+
!equality.equal(data, {}) &&
|
|
4622
|
+
!returnPartialData) {
|
|
4564
4623
|
process.env.NODE_ENV === "production" || tsInvariant.invariant.warn("Missing cache result fields: " + diff.missing.map(function (m) { return m.path.join('.'); }).join(', '), diff.missing);
|
|
4565
4624
|
}
|
|
4566
4625
|
var fromData = function (data) { return Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
@@ -4640,7 +4699,7 @@ var QueryManager = (function () {
|
|
|
4640
4699
|
return QueryManager;
|
|
4641
4700
|
}());
|
|
4642
4701
|
function markMutationResult(mutation, cache) {
|
|
4643
|
-
if (
|
|
4702
|
+
if (shouldWriteResult(mutation.result, mutation.errorPolicy)) {
|
|
4644
4703
|
var cacheWrites_1 = [{
|
|
4645
4704
|
result: mutation.result.data,
|
|
4646
4705
|
dataId: 'ROOT_MUTATION',
|
|
@@ -4699,7 +4758,7 @@ var ApolloClient = (function () {
|
|
|
4699
4758
|
: ApolloLink.empty();
|
|
4700
4759
|
}
|
|
4701
4760
|
if (!cache) {
|
|
4702
|
-
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(
|
|
4761
|
+
throw process.env.NODE_ENV === "production" ? new tsInvariant.InvariantError(9) : new tsInvariant.InvariantError("To initialize Apollo Client, you must specify a 'cache' property " +
|
|
4703
4762
|
"in the options object. \n" +
|
|
4704
4763
|
"For more information, please visit: https://go.apollo.dev/c/docs");
|
|
4705
4764
|
}
|
|
@@ -4791,7 +4850,7 @@ var ApolloClient = (function () {
|
|
|
4791
4850
|
if (this.defaultOptions.query) {
|
|
4792
4851
|
options = compact(this.defaultOptions.query, options);
|
|
4793
4852
|
}
|
|
4794
|
-
process.env.NODE_ENV === "production" ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network',
|
|
4853
|
+
process.env.NODE_ENV === "production" ? tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 10) : tsInvariant.invariant(options.fetchPolicy !== 'cache-and-network', 'The cache-and-network fetchPolicy does not work with client.query, because ' +
|
|
4795
4854
|
'client.query can only return a single result. Please use client.watchQuery ' +
|
|
4796
4855
|
'to receive multiple results from the cache and the network, or consider ' +
|
|
4797
4856
|
'using a different fetchPolicy, such as cache-first or network-only.');
|
|
@@ -5454,12 +5513,12 @@ var QueryData = (function (_super) {
|
|
|
5454
5513
|
}
|
|
5455
5514
|
};
|
|
5456
5515
|
QueryData.prototype.updateObservableQuery = function () {
|
|
5457
|
-
if (this.getOptions().skip)
|
|
5458
|
-
return;
|
|
5459
5516
|
if (!this.currentObservable) {
|
|
5460
5517
|
this.initializeObservableQuery();
|
|
5461
5518
|
return;
|
|
5462
5519
|
}
|
|
5520
|
+
if (this.getOptions().skip)
|
|
5521
|
+
return;
|
|
5463
5522
|
var newObservableQueryOptions = tslib.__assign(tslib.__assign({}, this.prepareObservableQueryOptions()), { children: null });
|
|
5464
5523
|
if (!equality.equal(newObservableQueryOptions, this.previousData.observableQueryOptions)) {
|
|
5465
5524
|
this.previousData.observableQueryOptions = newObservableQueryOptions;
|