@apollo/client 3.5.10 → 3.6.0-beta.10
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 +387 -286
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +2 -2
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +8 -2
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +75 -32
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js +4 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +5 -2
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +18 -11
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +98 -48
- package/core/core.cjs.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.d.ts.map +1 -1
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/watchQueryOptions.d.ts +8 -1
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/batch/batch.cjs +47 -37
- package/link/batch/batch.cjs.map +1 -1
- package/link/batch/batching.d.ts +2 -6
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch/batching.js +47 -37
- package/link/batch/batching.js.map +1 -1
- package/package.json +17 -16
- package/react/hooks/hooks.cjs +262 -209
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/options.d.ts +3 -0
- package/react/hooks/options.d.ts.map +1 -0
- package/react/hooks/options.js +20 -0
- package/react/hooks/options.js.map +1 -0
- package/react/hooks/useLazyQuery.d.ts +2 -2
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +3 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +2 -2
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +237 -205
- package/react/hooks/useQuery.js.map +1 -1
- package/react/ssr/RenderPromises.d.ts +1 -1
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js +2 -2
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/ssr.cjs +2 -2
- package/react/ssr/ssr.cjs.map +1 -1
- package/react/types/types.d.ts +3 -0
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/mocking/mockFetch.js +1 -1
- package/testing/core/mocking/mockFetch.js.map +1 -1
- package/version.js +1 -1
package/apollo-client.cjs
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
6
|
var tsInvariant = require('ts-invariant');
|
|
7
|
-
var
|
|
7
|
+
var equal = require('@wry/equality');
|
|
8
8
|
var zenObservableTs = require('zen-observable-ts');
|
|
9
9
|
require('symbol-observable');
|
|
10
10
|
var graphql = require('graphql');
|
|
@@ -14,6 +14,8 @@ var trie = require('@wry/trie');
|
|
|
14
14
|
var graphqlTag = require('graphql-tag');
|
|
15
15
|
var React = require('react');
|
|
16
16
|
|
|
17
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
18
|
+
|
|
17
19
|
function _interopNamespace(e) {
|
|
18
20
|
if (e && e.__esModule) return e;
|
|
19
21
|
var n = Object.create(null);
|
|
@@ -26,6 +28,7 @@ function _interopNamespace(e) {
|
|
|
26
28
|
return Object.freeze(n);
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
29
32
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
30
33
|
|
|
31
34
|
function maybe(thunk) {
|
|
@@ -703,7 +706,7 @@ function removeClientSetsFromDocument(document) {
|
|
|
703
706
|
return modifiedDoc;
|
|
704
707
|
}
|
|
705
708
|
|
|
706
|
-
var hasOwnProperty$
|
|
709
|
+
var hasOwnProperty$4 = Object.prototype.hasOwnProperty;
|
|
707
710
|
function mergeDeep() {
|
|
708
711
|
var sources = [];
|
|
709
712
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
@@ -740,7 +743,7 @@ var DeepMerger = (function () {
|
|
|
740
743
|
}
|
|
741
744
|
if (isNonNullObject(source) && isNonNullObject(target)) {
|
|
742
745
|
Object.keys(source).forEach(function (sourceKey) {
|
|
743
|
-
if (hasOwnProperty$
|
|
746
|
+
if (hasOwnProperty$4.call(target, sourceKey)) {
|
|
744
747
|
var targetValue = target[sourceKey];
|
|
745
748
|
if (source[sourceKey] !== targetValue) {
|
|
746
749
|
var result = _this.reconciler.apply(_this, tslib.__spreadArray([target, source, sourceKey], context, false));
|
|
@@ -1291,9 +1294,9 @@ var concat = ApolloLink.concat;
|
|
|
1291
1294
|
|
|
1292
1295
|
var execute = ApolloLink.execute;
|
|
1293
1296
|
|
|
1294
|
-
var version = '3.
|
|
1297
|
+
var version = '3.6.0-beta.10';
|
|
1295
1298
|
|
|
1296
|
-
var hasOwnProperty$
|
|
1299
|
+
var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1297
1300
|
function parseAndCheckHttpResponse(operations) {
|
|
1298
1301
|
return function (response) { return response
|
|
1299
1302
|
.text()
|
|
@@ -1315,8 +1318,8 @@ function parseAndCheckHttpResponse(operations) {
|
|
|
1315
1318
|
throwServerError(response, result, "Response not successful: Received status code ".concat(response.status));
|
|
1316
1319
|
}
|
|
1317
1320
|
if (!Array.isArray(result) &&
|
|
1318
|
-
!hasOwnProperty$
|
|
1319
|
-
!hasOwnProperty$
|
|
1321
|
+
!hasOwnProperty$3.call(result, 'data') &&
|
|
1322
|
+
!hasOwnProperty$3.call(result, 'errors')) {
|
|
1320
1323
|
throwServerError(response, result, "Server response was missing for query '".concat(Array.isArray(operations)
|
|
1321
1324
|
? operations.map(function (op) { return op.operationName; })
|
|
1322
1325
|
: operations.operationName, "'."));
|
|
@@ -2159,7 +2162,7 @@ var Layer = (function (_super) {
|
|
|
2159
2162
|
}
|
|
2160
2163
|
else if (ownStoreObject !== parentStoreObject) {
|
|
2161
2164
|
Object.keys(ownStoreObject).forEach(function (storeFieldName) {
|
|
2162
|
-
if (!
|
|
2165
|
+
if (!equal.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
|
|
2163
2166
|
_this.group.dirty(dataId, storeFieldName);
|
|
2164
2167
|
}
|
|
2165
2168
|
});
|
|
@@ -2203,7 +2206,7 @@ var Stump = (function (_super) {
|
|
|
2203
2206
|
function storeObjectReconciler(existingObject, incomingObject, property) {
|
|
2204
2207
|
var existingValue = existingObject[property];
|
|
2205
2208
|
var incomingValue = incomingObject[property];
|
|
2206
|
-
return
|
|
2209
|
+
return equal.equal(existingValue, incomingValue) ? existingValue : incomingValue;
|
|
2207
2210
|
}
|
|
2208
2211
|
function supportsResultCaching(store) {
|
|
2209
2212
|
return !!(store instanceof EntityStore && store.group.caching);
|
|
@@ -3533,7 +3536,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
3533
3536
|
return;
|
|
3534
3537
|
if (isReference(existing))
|
|
3535
3538
|
return;
|
|
3536
|
-
if (
|
|
3539
|
+
if (equal.equal(existing, incoming))
|
|
3537
3540
|
return;
|
|
3538
3541
|
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
3539
3542
|
return;
|
|
@@ -3847,7 +3850,7 @@ var InMemoryCache = (function (_super) {
|
|
|
3847
3850
|
return;
|
|
3848
3851
|
}
|
|
3849
3852
|
}
|
|
3850
|
-
if (!lastDiff || !
|
|
3853
|
+
if (!lastDiff || !equal.equal(lastDiff.result, diff.result)) {
|
|
3851
3854
|
c.callback(c.lastDiff = diff, lastDiff);
|
|
3852
3855
|
}
|
|
3853
3856
|
};
|
|
@@ -3905,8 +3908,7 @@ function isNetworkRequestInFlight(networkStatus) {
|
|
|
3905
3908
|
return networkStatus ? networkStatus < 7 : false;
|
|
3906
3909
|
}
|
|
3907
3910
|
|
|
3908
|
-
var assign = Object.assign, hasOwnProperty$
|
|
3909
|
-
var warnedAboutUpdateQuery = false;
|
|
3911
|
+
var assign = Object.assign, hasOwnProperty$2 = Object.hasOwnProperty;
|
|
3910
3912
|
var ObservableQuery = (function (_super) {
|
|
3911
3913
|
tslib.__extends(ObservableQuery, _super);
|
|
3912
3914
|
function ObservableQuery(_a) {
|
|
@@ -3992,7 +3994,7 @@ var ObservableQuery = (function (_super) {
|
|
|
3992
3994
|
if (diff.complete || this.options.returnPartialData) {
|
|
3993
3995
|
result.data = diff.result;
|
|
3994
3996
|
}
|
|
3995
|
-
if (
|
|
3997
|
+
if (equal.equal(result.data, {})) {
|
|
3996
3998
|
result.data = void 0;
|
|
3997
3999
|
}
|
|
3998
4000
|
if (diff.complete) {
|
|
@@ -4023,13 +4025,13 @@ var ObservableQuery = (function (_super) {
|
|
|
4023
4025
|
return result;
|
|
4024
4026
|
};
|
|
4025
4027
|
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
|
|
4026
|
-
return !this.last || !
|
|
4028
|
+
return !this.last || !equal.equal(this.last.result, newResult);
|
|
4027
4029
|
};
|
|
4028
4030
|
ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
|
|
4029
4031
|
var last = this.last;
|
|
4030
4032
|
if (last &&
|
|
4031
4033
|
last[key] &&
|
|
4032
|
-
(!variablesMustMatch ||
|
|
4034
|
+
(!variablesMustMatch || equal.equal(last.variables, this.variables))) {
|
|
4033
4035
|
return last[key];
|
|
4034
4036
|
}
|
|
4035
4037
|
};
|
|
@@ -4061,14 +4063,14 @@ var ObservableQuery = (function (_super) {
|
|
|
4061
4063
|
else {
|
|
4062
4064
|
reobserveOptions.fetchPolicy = 'network-only';
|
|
4063
4065
|
}
|
|
4064
|
-
if (__DEV__ && variables && hasOwnProperty$
|
|
4066
|
+
if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
|
|
4065
4067
|
var queryDef = getQueryDefinition(this.options.query);
|
|
4066
4068
|
var vars = queryDef.variableDefinitions;
|
|
4067
4069
|
if (!vars || !vars.some(function (v) { return v.variable.name.value === "variables"; })) {
|
|
4068
4070
|
__DEV__ && tsInvariant.invariant.warn("Called refetch(".concat(JSON.stringify(variables), ") for query ").concat(((_a = queryDef.name) === null || _a === void 0 ? void 0 : _a.value) || JSON.stringify(queryDef), ", which does not declare a $variables variable.\nDid you mean to call refetch(variables) instead of refetch({ variables })?"));
|
|
4069
4071
|
}
|
|
4070
4072
|
}
|
|
4071
|
-
if (variables && !
|
|
4073
|
+
if (variables && !equal.equal(this.options.variables, variables)) {
|
|
4072
4074
|
reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
4073
4075
|
}
|
|
4074
4076
|
this.queryInfo.resetLastWrite();
|
|
@@ -4078,35 +4080,49 @@ var ObservableQuery = (function (_super) {
|
|
|
4078
4080
|
var _this = this;
|
|
4079
4081
|
var combinedOptions = tslib.__assign(tslib.__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : tslib.__assign(tslib.__assign(tslib.__assign({}, this.options), fetchMoreOptions), { variables: tslib.__assign(tslib.__assign({}, this.options.variables), fetchMoreOptions.variables) }))), { fetchPolicy: "no-cache" });
|
|
4080
4082
|
var qid = this.queryManager.generateQueryId();
|
|
4083
|
+
var queryInfo = this.queryInfo;
|
|
4084
|
+
var originalNetworkStatus = queryInfo.networkStatus;
|
|
4085
|
+
queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
4081
4086
|
if (combinedOptions.notifyOnNetworkStatusChange) {
|
|
4082
|
-
this.queryInfo.networkStatus = exports.NetworkStatus.fetchMore;
|
|
4083
4087
|
this.observe();
|
|
4084
4088
|
}
|
|
4089
|
+
var updatedQuerySet = new Set();
|
|
4085
4090
|
return this.queryManager.fetchQuery(qid, combinedOptions, exports.NetworkStatus.fetchMore).then(function (fetchMoreResult) {
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4091
|
+
_this.queryManager.removeQuery(qid);
|
|
4092
|
+
if (queryInfo.networkStatus === exports.NetworkStatus.fetchMore) {
|
|
4093
|
+
queryInfo.networkStatus = originalNetworkStatus;
|
|
4094
|
+
}
|
|
4095
|
+
_this.queryManager.cache.batch({
|
|
4096
|
+
update: function (cache) {
|
|
4097
|
+
var updateQuery = fetchMoreOptions.updateQuery;
|
|
4098
|
+
if (updateQuery) {
|
|
4099
|
+
cache.updateQuery({
|
|
4100
|
+
query: _this.options.query,
|
|
4101
|
+
variables: _this.variables,
|
|
4102
|
+
returnPartialData: true,
|
|
4103
|
+
optimistic: false,
|
|
4104
|
+
}, function (previous) { return updateQuery(previous, {
|
|
4105
|
+
fetchMoreResult: fetchMoreResult.data,
|
|
4106
|
+
variables: combinedOptions.variables,
|
|
4107
|
+
}); });
|
|
4108
|
+
}
|
|
4109
|
+
else {
|
|
4110
|
+
cache.writeQuery({
|
|
4111
|
+
query: combinedOptions.query,
|
|
4112
|
+
variables: combinedOptions.variables,
|
|
4113
|
+
data: fetchMoreResult.data,
|
|
4114
|
+
});
|
|
4115
|
+
}
|
|
4116
|
+
},
|
|
4117
|
+
onWatchUpdated: function (watch) {
|
|
4118
|
+
updatedQuerySet.add(watch.query);
|
|
4119
|
+
},
|
|
4120
|
+
});
|
|
4106
4121
|
return fetchMoreResult;
|
|
4107
4122
|
}).finally(function () {
|
|
4108
|
-
_this.
|
|
4109
|
-
|
|
4123
|
+
if (!updatedQuerySet.has(_this.options.query)) {
|
|
4124
|
+
reobserveCacheFirst(_this);
|
|
4125
|
+
}
|
|
4110
4126
|
});
|
|
4111
4127
|
};
|
|
4112
4128
|
ObservableQuery.prototype.subscribeToMore = function (options) {
|
|
@@ -4149,7 +4165,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4149
4165
|
return this.reobserve(newOptions);
|
|
4150
4166
|
};
|
|
4151
4167
|
ObservableQuery.prototype.setVariables = function (variables) {
|
|
4152
|
-
if (
|
|
4168
|
+
if (equal.equal(this.variables, variables)) {
|
|
4153
4169
|
return this.observers.size
|
|
4154
4170
|
? this.result()
|
|
4155
4171
|
: Promise.resolve();
|
|
@@ -4191,6 +4207,27 @@ var ObservableQuery = (function (_super) {
|
|
|
4191
4207
|
this.options.pollInterval = 0;
|
|
4192
4208
|
this.updatePolling();
|
|
4193
4209
|
};
|
|
4210
|
+
ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
|
|
4211
|
+
if (options === void 0) { options = this.options; }
|
|
4212
|
+
if (options.nextFetchPolicy) {
|
|
4213
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
|
|
4214
|
+
if (typeof options.nextFetchPolicy === "function") {
|
|
4215
|
+
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
4216
|
+
reason: reason,
|
|
4217
|
+
options: options,
|
|
4218
|
+
observable: this,
|
|
4219
|
+
initialPolicy: this.initialFetchPolicy,
|
|
4220
|
+
});
|
|
4221
|
+
}
|
|
4222
|
+
else if (reason === "variables-changed") {
|
|
4223
|
+
options.fetchPolicy = this.initialFetchPolicy;
|
|
4224
|
+
}
|
|
4225
|
+
else {
|
|
4226
|
+
options.fetchPolicy = options.nextFetchPolicy;
|
|
4227
|
+
}
|
|
4228
|
+
}
|
|
4229
|
+
return options.fetchPolicy;
|
|
4230
|
+
};
|
|
4194
4231
|
ObservableQuery.prototype.fetch = function (options, newNetworkStatus) {
|
|
4195
4232
|
this.queryManager.setObservableQuery(this);
|
|
4196
4233
|
return this.queryManager.fetchQueryObservable(this.queryId, options, newNetworkStatus);
|
|
@@ -4261,8 +4298,8 @@ var ObservableQuery = (function (_super) {
|
|
|
4261
4298
|
if (newOptions &&
|
|
4262
4299
|
newOptions.variables &&
|
|
4263
4300
|
!newOptions.fetchPolicy &&
|
|
4264
|
-
!
|
|
4265
|
-
|
|
4301
|
+
!equal.equal(newOptions.variables, oldVariables)) {
|
|
4302
|
+
this.applyNextFetchPolicy("variables-changed");
|
|
4266
4303
|
if (newNetworkStatus === void 0) {
|
|
4267
4304
|
newNetworkStatus = exports.NetworkStatus.setVariables;
|
|
4268
4305
|
}
|
|
@@ -4326,6 +4363,23 @@ var ObservableQuery = (function (_super) {
|
|
|
4326
4363
|
return ObservableQuery;
|
|
4327
4364
|
}(zenObservableTs.Observable));
|
|
4328
4365
|
fixObservableSubclass(ObservableQuery);
|
|
4366
|
+
function reobserveCacheFirst(obsQuery) {
|
|
4367
|
+
var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
|
|
4368
|
+
if (fetchPolicy === "cache-and-network" ||
|
|
4369
|
+
fetchPolicy === "network-only") {
|
|
4370
|
+
return obsQuery.reobserve({
|
|
4371
|
+
fetchPolicy: "cache-first",
|
|
4372
|
+
nextFetchPolicy: function () {
|
|
4373
|
+
this.nextFetchPolicy = nextFetchPolicy;
|
|
4374
|
+
if (typeof nextFetchPolicy === "function") {
|
|
4375
|
+
return nextFetchPolicy.apply(this, arguments);
|
|
4376
|
+
}
|
|
4377
|
+
return fetchPolicy;
|
|
4378
|
+
},
|
|
4379
|
+
});
|
|
4380
|
+
}
|
|
4381
|
+
return obsQuery.reobserve();
|
|
4382
|
+
}
|
|
4329
4383
|
function defaultSubscriptionObserverErrorCallback(error) {
|
|
4330
4384
|
__DEV__ && tsInvariant.invariant.error('Unhandled error', error.message, error.stack);
|
|
4331
4385
|
}
|
|
@@ -4334,14 +4388,6 @@ function logMissingFieldErrors(missing) {
|
|
|
4334
4388
|
__DEV__ && tsInvariant.invariant.debug("Missing cache result fields: ".concat(JSON.stringify(missing)), missing);
|
|
4335
4389
|
}
|
|
4336
4390
|
}
|
|
4337
|
-
function applyNextFetchPolicy(options) {
|
|
4338
|
-
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, nextFetchPolicy = options.nextFetchPolicy;
|
|
4339
|
-
if (nextFetchPolicy) {
|
|
4340
|
-
options.fetchPolicy = typeof nextFetchPolicy === "function"
|
|
4341
|
-
? nextFetchPolicy.call(options, fetchPolicy)
|
|
4342
|
-
: nextFetchPolicy;
|
|
4343
|
-
}
|
|
4344
|
-
}
|
|
4345
4391
|
|
|
4346
4392
|
var LocalState = (function () {
|
|
4347
4393
|
function LocalState(_a) {
|
|
@@ -4643,10 +4689,10 @@ var QueryInfo = (function () {
|
|
|
4643
4689
|
var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
|
|
4644
4690
|
if (this.variables &&
|
|
4645
4691
|
this.networkStatus !== exports.NetworkStatus.loading &&
|
|
4646
|
-
!
|
|
4692
|
+
!equal.equal(this.variables, query.variables)) {
|
|
4647
4693
|
networkStatus = exports.NetworkStatus.setVariables;
|
|
4648
4694
|
}
|
|
4649
|
-
if (!
|
|
4695
|
+
if (!equal.equal(query.variables, this.variables)) {
|
|
4650
4696
|
this.lastDiff = void 0;
|
|
4651
4697
|
}
|
|
4652
4698
|
Object.assign(this, {
|
|
@@ -4672,7 +4718,7 @@ var QueryInfo = (function () {
|
|
|
4672
4718
|
QueryInfo.prototype.getDiff = function (variables) {
|
|
4673
4719
|
if (variables === void 0) { variables = this.variables; }
|
|
4674
4720
|
var options = this.getDiffOptions(variables);
|
|
4675
|
-
if (this.lastDiff &&
|
|
4721
|
+
if (this.lastDiff && equal.equal(options, this.lastDiff.options)) {
|
|
4676
4722
|
return this.lastDiff.diff;
|
|
4677
4723
|
}
|
|
4678
4724
|
this.updateWatch(this.variables = variables);
|
|
@@ -4706,7 +4752,7 @@ var QueryInfo = (function () {
|
|
|
4706
4752
|
var oldDiff = this.lastDiff && this.lastDiff.diff;
|
|
4707
4753
|
this.updateLastDiff(diff);
|
|
4708
4754
|
if (!this.dirty &&
|
|
4709
|
-
!
|
|
4755
|
+
!equal.equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
|
4710
4756
|
this.dirty = true;
|
|
4711
4757
|
if (!this.notifyTimeout) {
|
|
4712
4758
|
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
@@ -4724,11 +4770,12 @@ var QueryInfo = (function () {
|
|
|
4724
4770
|
if (oq) {
|
|
4725
4771
|
oq["queryInfo"] = this;
|
|
4726
4772
|
this.listeners.add(this.oqListener = function () {
|
|
4727
|
-
|
|
4773
|
+
var diff = _this.getDiff();
|
|
4774
|
+
if (diff.fromOptimisticTransaction) {
|
|
4728
4775
|
oq["observe"]();
|
|
4729
4776
|
}
|
|
4730
4777
|
else {
|
|
4731
|
-
oq
|
|
4778
|
+
reobserveCacheFirst(oq);
|
|
4732
4779
|
}
|
|
4733
4780
|
});
|
|
4734
4781
|
}
|
|
@@ -4780,7 +4827,7 @@ var QueryInfo = (function () {
|
|
|
4780
4827
|
}
|
|
4781
4828
|
var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
|
4782
4829
|
if (!this.lastWatch ||
|
|
4783
|
-
!
|
|
4830
|
+
!equal.equal(watchOptions, this.lastWatch)) {
|
|
4784
4831
|
this.cancel();
|
|
4785
4832
|
this.cancel = this.cache.watch(this.lastWatch = watchOptions);
|
|
4786
4833
|
}
|
|
@@ -4792,8 +4839,8 @@ var QueryInfo = (function () {
|
|
|
4792
4839
|
var lastWrite = this.lastWrite;
|
|
4793
4840
|
return !(lastWrite &&
|
|
4794
4841
|
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
4795
|
-
|
|
4796
|
-
|
|
4842
|
+
equal.equal(variables, lastWrite.variables) &&
|
|
4843
|
+
equal.equal(result.data, lastWrite.result.data));
|
|
4797
4844
|
};
|
|
4798
4845
|
QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
|
|
4799
4846
|
var _this = this;
|
|
@@ -4870,10 +4917,10 @@ function shouldWriteResult(result, errorPolicy) {
|
|
|
4870
4917
|
return writeWithErrors;
|
|
4871
4918
|
}
|
|
4872
4919
|
|
|
4873
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
4920
|
+
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
4874
4921
|
var QueryManager = (function () {
|
|
4875
4922
|
function QueryManager(_a) {
|
|
4876
|
-
var cache = _a.cache, link = _a.link, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
|
|
4923
|
+
var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, assumeImmutableResults = _a.assumeImmutableResults;
|
|
4877
4924
|
this.clientAwareness = {};
|
|
4878
4925
|
this.queries = new Map();
|
|
4879
4926
|
this.fetchCancelFns = new Map();
|
|
@@ -4884,6 +4931,7 @@ var QueryManager = (function () {
|
|
|
4884
4931
|
this.inFlightLinkObservables = new Map();
|
|
4885
4932
|
this.cache = cache;
|
|
4886
4933
|
this.link = link;
|
|
4934
|
+
this.defaultOptions = defaultOptions || Object.create(null);
|
|
4887
4935
|
this.queryDeduplication = queryDeduplication;
|
|
4888
4936
|
this.clientAwareness = clientAwareness;
|
|
4889
4937
|
this.localState = localState || new LocalState({ cache: cache });
|
|
@@ -4905,11 +4953,12 @@ var QueryManager = (function () {
|
|
|
4905
4953
|
this.fetchCancelFns.clear();
|
|
4906
4954
|
};
|
|
4907
4955
|
QueryManager.prototype.mutate = function (_a) {
|
|
4908
|
-
var
|
|
4956
|
+
var _b, _c;
|
|
4957
|
+
var mutation = _a.mutation, variables = _a.variables, optimisticResponse = _a.optimisticResponse, updateQueries = _a.updateQueries, _d = _a.refetchQueries, refetchQueries = _d === void 0 ? [] : _d, _e = _a.awaitRefetchQueries, awaitRefetchQueries = _e === void 0 ? false : _e, updateWithProxyFn = _a.update, onQueryUpdated = _a.onQueryUpdated, _f = _a.fetchPolicy, fetchPolicy = _f === void 0 ? ((_b = this.defaultOptions.mutate) === null || _b === void 0 ? void 0 : _b.fetchPolicy) || "network-only" : _f, _g = _a.errorPolicy, errorPolicy = _g === void 0 ? ((_c = this.defaultOptions.mutate) === null || _c === void 0 ? void 0 : _c.errorPolicy) || "none" : _g, keepRootFields = _a.keepRootFields, context = _a.context;
|
|
4909
4958
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
4910
4959
|
var mutationId, mutationStoreValue, self;
|
|
4911
|
-
return tslib.__generator(this, function (
|
|
4912
|
-
switch (
|
|
4960
|
+
return tslib.__generator(this, function (_h) {
|
|
4961
|
+
switch (_h.label) {
|
|
4913
4962
|
case 0:
|
|
4914
4963
|
__DEV__ ? tsInvariant.invariant(mutation, 'mutation option is required. You must specify your GraphQL document in the mutation option.') : tsInvariant.invariant(mutation, 12);
|
|
4915
4964
|
__DEV__ ? tsInvariant.invariant(fetchPolicy === 'network-only' ||
|
|
@@ -4921,8 +4970,8 @@ var QueryManager = (function () {
|
|
|
4921
4970
|
if (!this.transform(mutation).hasClientExports) return [3, 2];
|
|
4922
4971
|
return [4, this.localState.addExportedVariables(mutation, variables, context)];
|
|
4923
4972
|
case 1:
|
|
4924
|
-
variables = (
|
|
4925
|
-
|
|
4973
|
+
variables = (_h.sent());
|
|
4974
|
+
_h.label = 2;
|
|
4926
4975
|
case 2:
|
|
4927
4976
|
mutationStoreValue = this.mutationStore &&
|
|
4928
4977
|
(this.mutationStore[mutationId] = {
|
|
@@ -5023,7 +5072,7 @@ var QueryManager = (function () {
|
|
|
5023
5072
|
this.queries.forEach(function (_a, queryId) {
|
|
5024
5073
|
var observableQuery = _a.observableQuery;
|
|
5025
5074
|
var queryName = observableQuery && observableQuery.queryName;
|
|
5026
|
-
if (!queryName || !hasOwnProperty.call(updateQueries_1, queryName)) {
|
|
5075
|
+
if (!queryName || !hasOwnProperty$1.call(updateQueries_1, queryName)) {
|
|
5027
5076
|
return;
|
|
5028
5077
|
}
|
|
5029
5078
|
var updater = updateQueries_1[queryName];
|
|
@@ -5375,8 +5424,10 @@ var QueryManager = (function () {
|
|
|
5375
5424
|
};
|
|
5376
5425
|
QueryManager.prototype.removeQuery = function (queryId) {
|
|
5377
5426
|
this.fetchCancelFns.delete(queryId);
|
|
5378
|
-
this.
|
|
5379
|
-
|
|
5427
|
+
if (this.queries.has(queryId)) {
|
|
5428
|
+
this.getQuery(queryId).stop();
|
|
5429
|
+
this.queries.delete(queryId);
|
|
5430
|
+
}
|
|
5380
5431
|
};
|
|
5381
5432
|
QueryManager.prototype.broadcastQueries = function () {
|
|
5382
5433
|
if (this.onBroadcast)
|
|
@@ -5482,7 +5533,8 @@ var QueryManager = (function () {
|
|
|
5482
5533
|
var query = this.transform(options.query).document;
|
|
5483
5534
|
var variables = this.getVariables(query, options.variables);
|
|
5484
5535
|
var queryInfo = this.getQuery(queryId);
|
|
5485
|
-
var
|
|
5536
|
+
var defaults = this.defaultOptions.watchQuery;
|
|
5537
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? defaults && defaults.fetchPolicy || "cache-first" : _a, _b = options.errorPolicy, errorPolicy = _b === void 0 ? defaults && defaults.errorPolicy || "none" : _b, _c = options.returnPartialData, returnPartialData = _c === void 0 ? false : _c, _d = options.notifyOnNetworkStatusChange, notifyOnNetworkStatusChange = _d === void 0 ? false : _d, _e = options.context, context = _e === void 0 ? {} : _e;
|
|
5486
5538
|
var normalized = Object.assign({}, options, {
|
|
5487
5539
|
query: query,
|
|
5488
5540
|
variables: variables,
|
|
@@ -5504,7 +5556,9 @@ var QueryManager = (function () {
|
|
|
5504
5556
|
: fromVariables(normalized.variables));
|
|
5505
5557
|
concast.cleanup(function () {
|
|
5506
5558
|
_this.fetchCancelFns.delete(queryId);
|
|
5507
|
-
|
|
5559
|
+
if (queryInfo.observableQuery) {
|
|
5560
|
+
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
5561
|
+
}
|
|
5508
5562
|
});
|
|
5509
5563
|
return concast;
|
|
5510
5564
|
};
|
|
@@ -5591,7 +5645,7 @@ var QueryManager = (function () {
|
|
|
5591
5645
|
var data = diff.result;
|
|
5592
5646
|
if (__DEV__ &&
|
|
5593
5647
|
!returnPartialData &&
|
|
5594
|
-
!
|
|
5648
|
+
!equal.equal(data, {})) {
|
|
5595
5649
|
logMissingFieldErrors(diff.missing);
|
|
5596
5650
|
}
|
|
5597
5651
|
var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
@@ -5700,7 +5754,6 @@ function mergeOptions(defaults, options) {
|
|
|
5700
5754
|
var ApolloClient = (function () {
|
|
5701
5755
|
function ApolloClient(options) {
|
|
5702
5756
|
var _this = this;
|
|
5703
|
-
this.defaultOptions = {};
|
|
5704
5757
|
this.resetStoreCallbacks = [];
|
|
5705
5758
|
this.clearStoreCallbacks = [];
|
|
5706
5759
|
var uri = options.uri, credentials = options.credentials, headers = options.headers, cache = options.cache, _a = options.ssrMode, ssrMode = _a === void 0 ? false : _a, _b = options.ssrForceFetchDelay, ssrForceFetchDelay = _b === void 0 ? 0 : _b, _c = options.connectToDevTools, connectToDevTools = _c === void 0 ? typeof window === 'object' &&
|
|
@@ -5721,7 +5774,7 @@ var ApolloClient = (function () {
|
|
|
5721
5774
|
this.cache = cache;
|
|
5722
5775
|
this.disableNetworkFetches = ssrMode || ssrForceFetchDelay > 0;
|
|
5723
5776
|
this.queryDeduplication = queryDeduplication;
|
|
5724
|
-
this.defaultOptions = defaultOptions ||
|
|
5777
|
+
this.defaultOptions = defaultOptions || Object.create(null);
|
|
5725
5778
|
this.typeDefs = typeDefs;
|
|
5726
5779
|
if (ssrForceFetchDelay) {
|
|
5727
5780
|
setTimeout(function () { return (_this.disableNetworkFetches = false); }, ssrForceFetchDelay);
|
|
@@ -5768,6 +5821,7 @@ var ApolloClient = (function () {
|
|
|
5768
5821
|
this.queryManager = new QueryManager({
|
|
5769
5822
|
cache: this.cache,
|
|
5770
5823
|
link: this.link,
|
|
5824
|
+
defaultOptions: this.defaultOptions,
|
|
5771
5825
|
queryDeduplication: queryDeduplication,
|
|
5772
5826
|
ssrMode: ssrMode,
|
|
5773
5827
|
clientAwareness: {
|
|
@@ -6054,227 +6108,274 @@ function verifyDocumentType(document, type) {
|
|
|
6054
6108
|
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
|
|
6055
6109
|
}
|
|
6056
6110
|
|
|
6057
|
-
function
|
|
6058
|
-
var
|
|
6059
|
-
var
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6111
|
+
function useNormalizedOptions(optionsOrFunction) {
|
|
6112
|
+
var optionsRef = React.useRef();
|
|
6113
|
+
var options = optionsRef.current || Object.create(null);
|
|
6114
|
+
if (typeof optionsOrFunction === "function") {
|
|
6115
|
+
var newOptions = optionsOrFunction(options);
|
|
6116
|
+
if (newOptions !== options) {
|
|
6117
|
+
Object.assign(options, newOptions, newOptions.variables && {
|
|
6118
|
+
variables: tslib.__assign(tslib.__assign({}, options.variables), newOptions.variables),
|
|
6119
|
+
});
|
|
6120
|
+
}
|
|
6121
|
+
}
|
|
6122
|
+
else if (optionsOrFunction && !equal__default(optionsOrFunction, options)) {
|
|
6123
|
+
options = optionsOrFunction;
|
|
6124
|
+
}
|
|
6125
|
+
return optionsRef.current = options;
|
|
6126
|
+
}
|
|
6127
|
+
|
|
6128
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
6129
|
+
function useQuery(query, optionsOrFunction) {
|
|
6130
|
+
var options = useNormalizedOptions(optionsOrFunction);
|
|
6131
|
+
return useInternalState(useApolloClient(options.client), query).useQuery(options);
|
|
6132
|
+
}
|
|
6133
|
+
function useInternalState(client, query) {
|
|
6134
|
+
var stateRef = React.useRef();
|
|
6135
|
+
if (!stateRef.current ||
|
|
6136
|
+
client !== stateRef.current.client ||
|
|
6137
|
+
query !== stateRef.current.query) {
|
|
6138
|
+
stateRef.current = new InternalState(client, query);
|
|
6139
|
+
}
|
|
6140
|
+
var state = stateRef.current;
|
|
6141
|
+
var _a = React.useState(0); _a[0]; var setTick = _a[1];
|
|
6142
|
+
state.forceUpdate = function () {
|
|
6143
|
+
setTick(function (tick) { return tick + 1; });
|
|
6144
|
+
};
|
|
6145
|
+
return state;
|
|
6146
|
+
}
|
|
6147
|
+
var InternalState = (function () {
|
|
6148
|
+
function InternalState(client, query) {
|
|
6149
|
+
this.client = client;
|
|
6150
|
+
this.query = query;
|
|
6151
|
+
this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
|
|
6152
|
+
verifyDocumentType(query, exports.DocumentType.Query);
|
|
6153
|
+
}
|
|
6154
|
+
InternalState.prototype.forceUpdate = function () {
|
|
6155
|
+
};
|
|
6156
|
+
InternalState.prototype.useQuery = function (options) {
|
|
6157
|
+
this.useOptions(options);
|
|
6158
|
+
var obsQuery = this.useObservableQuery();
|
|
6159
|
+
this.useSubscriptionEffect(obsQuery);
|
|
6160
|
+
var result = this.getCurrentResult();
|
|
6161
|
+
this.unsafeHandlePartialRefetch(result);
|
|
6162
|
+
return this.toQueryResult(result);
|
|
6163
|
+
};
|
|
6164
|
+
InternalState.prototype.useOptions = function (options) {
|
|
6165
|
+
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6166
|
+
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6167
|
+
if (!equal.equal(watchQueryOptions, this.watchQueryOptions)) {
|
|
6168
|
+
this.watchQueryOptions = watchQueryOptions;
|
|
6169
|
+
}
|
|
6170
|
+
this.ssrDisabled = !!(options && (options.ssr === false ||
|
|
6171
|
+
options.skip));
|
|
6172
|
+
this.onCompleted = options
|
|
6173
|
+
&& options.onCompleted
|
|
6174
|
+
|| InternalState.prototype.onCompleted;
|
|
6175
|
+
this.onError = options
|
|
6176
|
+
&& options.onError
|
|
6177
|
+
|| InternalState.prototype.onError;
|
|
6178
|
+
};
|
|
6179
|
+
InternalState.prototype.createWatchQueryOptions = function (_a) {
|
|
6180
|
+
var _b;
|
|
6181
|
+
if (_a === void 0) { _a = {}; }
|
|
6182
|
+
var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
|
|
6183
|
+
var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
|
|
6184
|
+
if (skip) {
|
|
6185
|
+
watchQueryOptions.fetchPolicy = 'standby';
|
|
6186
|
+
}
|
|
6187
|
+
else if (((_b = watchQueryOptions.context) === null || _b === void 0 ? void 0 : _b.renderPromises) &&
|
|
6188
|
+
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
6189
|
+
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
6190
|
+
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6191
|
+
}
|
|
6192
|
+
else if (!watchQueryOptions.fetchPolicy) {
|
|
6193
|
+
var defaultOptions = this.client.defaultOptions.watchQuery;
|
|
6194
|
+
watchQueryOptions.fetchPolicy =
|
|
6195
|
+
defaultOptions && defaultOptions.fetchPolicy || 'cache-first';
|
|
6196
|
+
}
|
|
6197
|
+
if (!watchQueryOptions.variables) {
|
|
6198
|
+
watchQueryOptions.variables = {};
|
|
6199
|
+
}
|
|
6200
|
+
return watchQueryOptions;
|
|
6201
|
+
};
|
|
6202
|
+
InternalState.prototype.onCompleted = function (data) { };
|
|
6203
|
+
InternalState.prototype.onError = function (error) { };
|
|
6204
|
+
InternalState.prototype.useObservableQuery = function () {
|
|
6205
|
+
var _this = this;
|
|
6206
|
+
var obsQuery = this.observable =
|
|
6207
|
+
this.renderPromises
|
|
6208
|
+
&& this.renderPromises.getSSRObservable(this.watchQueryOptions)
|
|
6209
|
+
|| this.observable
|
|
6210
|
+
|| this.client.watchQuery(this.watchQueryOptions);
|
|
6211
|
+
this.obsQueryFields = React.useMemo(function () { return ({
|
|
6212
|
+
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6213
|
+
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
6214
|
+
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
6215
|
+
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
6216
|
+
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6217
|
+
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6218
|
+
}); }, [obsQuery]);
|
|
6219
|
+
if (this.renderPromises) {
|
|
6220
|
+
this.renderPromises.registerSSRObservable(obsQuery);
|
|
6221
|
+
if (!this.ssrDisabled && obsQuery.getCurrentResult().loading) {
|
|
6222
|
+
this.renderPromises.addQueryPromise({
|
|
6223
|
+
getOptions: function () { return obsQuery.options; },
|
|
6224
|
+
fetchData: function () { return new Promise(function (resolve) {
|
|
6225
|
+
var sub = obsQuery.subscribe({
|
|
6226
|
+
next: function (result) {
|
|
6227
|
+
if (!result.loading) {
|
|
6228
|
+
resolve();
|
|
6229
|
+
sub.unsubscribe();
|
|
6230
|
+
}
|
|
6231
|
+
},
|
|
6232
|
+
error: function () {
|
|
6085
6233
|
resolve();
|
|
6086
6234
|
sub.unsubscribe();
|
|
6087
|
-
}
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
});
|
|
6097
|
-
}); },
|
|
6098
|
-
}, function () { return null; });
|
|
6235
|
+
},
|
|
6236
|
+
complete: function () {
|
|
6237
|
+
resolve();
|
|
6238
|
+
},
|
|
6239
|
+
});
|
|
6240
|
+
}); },
|
|
6241
|
+
}, function () { return null; });
|
|
6242
|
+
obsQuery.setOptions(this.watchQueryOptions).catch(function () { });
|
|
6243
|
+
}
|
|
6099
6244
|
}
|
|
6245
|
+
var prevOptionsRef = React.useRef({
|
|
6246
|
+
watchQueryOptions: this.watchQueryOptions,
|
|
6247
|
+
});
|
|
6248
|
+
React.useEffect(function () {
|
|
6249
|
+
if (_this.renderPromises) ;
|
|
6250
|
+
else if (_this.watchQueryOptions !== prevOptionsRef.current.watchQueryOptions) {
|
|
6251
|
+
obsQuery.setOptions(_this.watchQueryOptions).catch(function () { });
|
|
6252
|
+
prevOptionsRef.current.watchQueryOptions = _this.watchQueryOptions;
|
|
6253
|
+
_this.setResult(obsQuery.getCurrentResult());
|
|
6254
|
+
}
|
|
6255
|
+
}, [obsQuery, this.watchQueryOptions]);
|
|
6100
6256
|
return obsQuery;
|
|
6101
|
-
}
|
|
6102
|
-
|
|
6103
|
-
var
|
|
6104
|
-
|
|
6105
|
-
|
|
6257
|
+
};
|
|
6258
|
+
InternalState.prototype.useSubscriptionEffect = function (obsQuery) {
|
|
6259
|
+
var _this = this;
|
|
6260
|
+
React.useEffect(function () {
|
|
6261
|
+
if (_this.renderPromises) {
|
|
6262
|
+
return;
|
|
6263
|
+
}
|
|
6264
|
+
var onNext = function () {
|
|
6265
|
+
var previousResult = _this.result;
|
|
6266
|
+
var result = obsQuery.getCurrentResult();
|
|
6267
|
+
if (previousResult &&
|
|
6268
|
+
previousResult.loading === result.loading &&
|
|
6269
|
+
previousResult.networkStatus === result.networkStatus &&
|
|
6270
|
+
equal.equal(previousResult.data, result.data)) {
|
|
6271
|
+
return;
|
|
6272
|
+
}
|
|
6273
|
+
_this.setResult(result);
|
|
6274
|
+
};
|
|
6275
|
+
var onError = function (error) {
|
|
6276
|
+
var last = obsQuery["last"];
|
|
6277
|
+
subscription.unsubscribe();
|
|
6278
|
+
try {
|
|
6279
|
+
obsQuery.resetLastResults();
|
|
6280
|
+
subscription = obsQuery.subscribe(onNext, onError);
|
|
6281
|
+
}
|
|
6282
|
+
finally {
|
|
6283
|
+
obsQuery["last"] = last;
|
|
6284
|
+
}
|
|
6285
|
+
if (!hasOwnProperty.call(error, 'graphQLErrors')) {
|
|
6286
|
+
throw error;
|
|
6287
|
+
}
|
|
6288
|
+
var previousResult = _this.result;
|
|
6289
|
+
if (!previousResult ||
|
|
6290
|
+
(previousResult && previousResult.loading) ||
|
|
6291
|
+
!equal.equal(error, previousResult.error)) {
|
|
6292
|
+
_this.setResult({
|
|
6293
|
+
data: (previousResult && previousResult.data),
|
|
6294
|
+
error: error,
|
|
6295
|
+
loading: false,
|
|
6296
|
+
networkStatus: exports.NetworkStatus.error,
|
|
6297
|
+
});
|
|
6298
|
+
}
|
|
6299
|
+
};
|
|
6300
|
+
var subscription = obsQuery.subscribe(onNext, onError);
|
|
6301
|
+
return function () { return subscription.unsubscribe(); };
|
|
6302
|
+
}, [
|
|
6303
|
+
obsQuery,
|
|
6304
|
+
this.renderPromises,
|
|
6305
|
+
this.client.disableNetworkFetches,
|
|
6306
|
+
]);
|
|
6307
|
+
};
|
|
6308
|
+
InternalState.prototype.setResult = function (nextResult) {
|
|
6309
|
+
var previousResult = this.result;
|
|
6310
|
+
if (previousResult && previousResult.data) {
|
|
6311
|
+
this.previousData = previousResult.data;
|
|
6312
|
+
}
|
|
6313
|
+
this.result = nextResult;
|
|
6314
|
+
this.forceUpdate();
|
|
6315
|
+
this.handleErrorOrCompleted(nextResult);
|
|
6316
|
+
};
|
|
6317
|
+
InternalState.prototype.handleErrorOrCompleted = function (result) {
|
|
6318
|
+
if (!result.loading) {
|
|
6106
6319
|
if (result.error) {
|
|
6107
|
-
|
|
6320
|
+
this.onError(result.error);
|
|
6108
6321
|
}
|
|
6109
6322
|
else if (result.data) {
|
|
6110
|
-
|
|
6323
|
+
this.onCompleted(result.data);
|
|
6111
6324
|
}
|
|
6112
6325
|
}
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
result: result,
|
|
6120
|
-
previousData: void 0,
|
|
6121
|
-
watchQueryOptions: createWatchQueryOptions(query, options, defaultWatchQueryOptions),
|
|
6122
|
-
});
|
|
6123
|
-
React.useEffect(function () {
|
|
6124
|
-
var _a, _b;
|
|
6125
|
-
var watchQueryOptions = createWatchQueryOptions(query, options, defaultWatchQueryOptions);
|
|
6126
|
-
var nextResult;
|
|
6127
|
-
if (ref.current.client !== client || !equality.equal(ref.current.query, query)) {
|
|
6128
|
-
var obsQuery_1 = client.watchQuery(watchQueryOptions);
|
|
6129
|
-
setObsQuery(obsQuery_1);
|
|
6130
|
-
nextResult = obsQuery_1.getCurrentResult();
|
|
6131
|
-
}
|
|
6132
|
-
else if (!equality.equal(ref.current.watchQueryOptions, watchQueryOptions)) {
|
|
6133
|
-
obsQuery.setOptions(watchQueryOptions).catch(function () { });
|
|
6134
|
-
nextResult = obsQuery.getCurrentResult();
|
|
6135
|
-
ref.current.watchQueryOptions = watchQueryOptions;
|
|
6136
|
-
}
|
|
6137
|
-
if (nextResult) {
|
|
6138
|
-
var previousResult = ref.current.result;
|
|
6139
|
-
if (previousResult.data) {
|
|
6140
|
-
ref.current.previousData = previousResult.data;
|
|
6141
|
-
}
|
|
6142
|
-
setResult(ref.current.result = nextResult);
|
|
6143
|
-
if (!nextResult.loading && options) {
|
|
6144
|
-
if (nextResult.error) {
|
|
6145
|
-
(_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, nextResult.error);
|
|
6146
|
-
}
|
|
6147
|
-
else if (nextResult.data) {
|
|
6148
|
-
(_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, nextResult.data);
|
|
6149
|
-
}
|
|
6150
|
-
}
|
|
6326
|
+
};
|
|
6327
|
+
InternalState.prototype.getCurrentResult = function () {
|
|
6328
|
+
var result = this.result;
|
|
6329
|
+
if (!result) {
|
|
6330
|
+
result = this.result = this.observable.getCurrentResult();
|
|
6331
|
+
this.handleErrorOrCompleted(result);
|
|
6151
6332
|
}
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6333
|
+
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
6334
|
+
this.queryHookOptions.ssr === false) {
|
|
6335
|
+
result = {
|
|
6336
|
+
loading: true,
|
|
6337
|
+
data: void 0,
|
|
6338
|
+
error: void 0,
|
|
6339
|
+
networkStatus: exports.NetworkStatus.loading,
|
|
6340
|
+
};
|
|
6157
6341
|
}
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
equality.equal(previousResult.data, result.data)) {
|
|
6167
|
-
return;
|
|
6168
|
-
}
|
|
6169
|
-
if (previousResult.data) {
|
|
6170
|
-
ref.current.previousData = previousResult.data;
|
|
6171
|
-
}
|
|
6172
|
-
setResult(ref.current.result = result);
|
|
6173
|
-
if (!result.loading) {
|
|
6174
|
-
(_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
|
|
6175
|
-
}
|
|
6342
|
+
else if (this.queryHookOptions.skip ||
|
|
6343
|
+
this.queryHookOptions.fetchPolicy === 'standby') {
|
|
6344
|
+
result = {
|
|
6345
|
+
loading: false,
|
|
6346
|
+
data: void 0,
|
|
6347
|
+
error: void 0,
|
|
6348
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
6349
|
+
};
|
|
6176
6350
|
}
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
}
|
|
6188
|
-
if (!error.hasOwnProperty('graphQLErrors')) {
|
|
6189
|
-
throw error;
|
|
6190
|
-
}
|
|
6191
|
-
var previousResult = ref.current.result;
|
|
6192
|
-
if ((previousResult && previousResult.loading) ||
|
|
6193
|
-
!equality.equal(error, previousResult.error)) {
|
|
6194
|
-
setResult(ref.current.result = {
|
|
6195
|
-
data: previousResult.data,
|
|
6196
|
-
error: error,
|
|
6197
|
-
loading: false,
|
|
6198
|
-
networkStatus: exports.NetworkStatus.error,
|
|
6199
|
-
});
|
|
6200
|
-
(_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
|
|
6201
|
-
}
|
|
6351
|
+
return result;
|
|
6352
|
+
};
|
|
6353
|
+
InternalState.prototype.toQueryResult = function (result) {
|
|
6354
|
+
var queryResult = this.toQueryResultCache.get(result);
|
|
6355
|
+
if (queryResult)
|
|
6356
|
+
return queryResult;
|
|
6357
|
+
var data = result.data; result.partial; var resultWithoutPartial = tslib.__rest(result, ["data", "partial"]);
|
|
6358
|
+
this.toQueryResultCache.set(result, queryResult = tslib.__assign(tslib.__assign(tslib.__assign({ data: data }, resultWithoutPartial), this.obsQueryFields), { client: this.client, observable: this.observable, variables: this.observable.variables, called: true, previousData: this.previousData }));
|
|
6359
|
+
if (!queryResult.error && isNonEmptyArray(result.errors)) {
|
|
6360
|
+
queryResult.error = new ApolloError({ graphQLErrors: result.errors });
|
|
6202
6361
|
}
|
|
6203
|
-
return
|
|
6204
|
-
}
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
if (partial &&
|
|
6209
|
-
(options === null || options === void 0 ? void 0 : options.partialRefetch) &&
|
|
6362
|
+
return queryResult;
|
|
6363
|
+
};
|
|
6364
|
+
InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
|
|
6365
|
+
if (result.partial &&
|
|
6366
|
+
this.queryHookOptions.partialRefetch &&
|
|
6210
6367
|
!result.loading &&
|
|
6211
6368
|
(!result.data || Object.keys(result.data).length === 0) &&
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
(
|
|
6218
|
-
!(options === null || options === void 0 ? void 0 : options.skip) &&
|
|
6219
|
-
result.loading) {
|
|
6220
|
-
obsQuery.setOptions(createWatchQueryOptions(query, options, defaultWatchQueryOptions)).catch(function () { });
|
|
6369
|
+
this.observable.options.fetchPolicy !== 'cache-only') {
|
|
6370
|
+
Object.assign(result, {
|
|
6371
|
+
loading: true,
|
|
6372
|
+
networkStatus: exports.NetworkStatus.refetch,
|
|
6373
|
+
});
|
|
6374
|
+
this.observable.refetch();
|
|
6221
6375
|
}
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
(options === null || options === void 0 ? void 0 : options.ssr) === false) {
|
|
6226
|
-
result = ref.current.result = {
|
|
6227
|
-
loading: true,
|
|
6228
|
-
data: void 0,
|
|
6229
|
-
error: void 0,
|
|
6230
|
-
networkStatus: exports.NetworkStatus.loading,
|
|
6231
|
-
};
|
|
6232
|
-
}
|
|
6233
|
-
else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
|
|
6234
|
-
result = {
|
|
6235
|
-
loading: false,
|
|
6236
|
-
data: void 0,
|
|
6237
|
-
error: void 0,
|
|
6238
|
-
networkStatus: exports.NetworkStatus.ready,
|
|
6239
|
-
};
|
|
6240
|
-
}
|
|
6241
|
-
if (result.errors && result.errors.length) {
|
|
6242
|
-
result = tslib.__assign(tslib.__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
|
|
6243
|
-
}
|
|
6244
|
-
var obsQueryFields = React.useMemo(function () { return ({
|
|
6245
|
-
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6246
|
-
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
6247
|
-
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
6248
|
-
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
6249
|
-
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6250
|
-
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6251
|
-
}); }, [obsQuery]);
|
|
6252
|
-
return tslib.__assign(tslib.__assign(tslib.__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options, defaultWatchQueryOptions).variables, client: client, called: true, previousData: ref.current.previousData }), result);
|
|
6253
|
-
}
|
|
6254
|
-
function createWatchQueryOptions(query, options, defaultOptions) {
|
|
6255
|
-
var _a;
|
|
6256
|
-
if (options === void 0) { options = {}; }
|
|
6257
|
-
var skip = options.skip; options.ssr; options.onCompleted; options.onError; options.displayName; var otherOptions = tslib.__rest(options, ["skip", "ssr", "onCompleted", "onError", "displayName"]);
|
|
6258
|
-
var watchQueryOptions = tslib.__assign({ query: query }, otherOptions);
|
|
6259
|
-
if (defaultOptions) {
|
|
6260
|
-
watchQueryOptions = mergeOptions(defaultOptions, watchQueryOptions);
|
|
6261
|
-
}
|
|
6262
|
-
if (skip) {
|
|
6263
|
-
watchQueryOptions.fetchPolicy = 'standby';
|
|
6264
|
-
}
|
|
6265
|
-
else if (((_a = watchQueryOptions.context) === null || _a === void 0 ? void 0 : _a.renderPromises) &&
|
|
6266
|
-
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
6267
|
-
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
6268
|
-
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6269
|
-
}
|
|
6270
|
-
else if (!watchQueryOptions.fetchPolicy) {
|
|
6271
|
-
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6272
|
-
}
|
|
6273
|
-
if (!watchQueryOptions.variables) {
|
|
6274
|
-
watchQueryOptions.variables = {};
|
|
6275
|
-
}
|
|
6276
|
-
return watchQueryOptions;
|
|
6277
|
-
}
|
|
6376
|
+
};
|
|
6377
|
+
return InternalState;
|
|
6378
|
+
}());
|
|
6278
6379
|
|
|
6279
6380
|
var EAGER_METHODS = [
|
|
6280
6381
|
'refetch',
|
|
@@ -6283,7 +6384,8 @@ var EAGER_METHODS = [
|
|
|
6283
6384
|
'startPolling',
|
|
6284
6385
|
'subscribeToMore',
|
|
6285
6386
|
];
|
|
6286
|
-
function useLazyQuery(query,
|
|
6387
|
+
function useLazyQuery(query, optionsOrFunction) {
|
|
6388
|
+
var options = useNormalizedOptions(optionsOrFunction);
|
|
6287
6389
|
var _a = React.useState({
|
|
6288
6390
|
called: false,
|
|
6289
6391
|
}), execution = _a[0], setExecution = _a[1];
|
|
@@ -6374,7 +6476,7 @@ function useMutation(mutation, options) {
|
|
|
6374
6476
|
error: error,
|
|
6375
6477
|
client: client,
|
|
6376
6478
|
};
|
|
6377
|
-
if (ref.current.isMounted && !
|
|
6479
|
+
if (ref.current.isMounted && !equal.equal(ref.current.result, result_1)) {
|
|
6378
6480
|
setResult(ref.current.result = result_1);
|
|
6379
6481
|
}
|
|
6380
6482
|
}
|
|
@@ -6392,7 +6494,7 @@ function useMutation(mutation, options) {
|
|
|
6392
6494
|
called: true,
|
|
6393
6495
|
client: client,
|
|
6394
6496
|
};
|
|
6395
|
-
if (!
|
|
6497
|
+
if (!equal.equal(ref.current.result, result_2)) {
|
|
6396
6498
|
setResult(ref.current.result = result_2);
|
|
6397
6499
|
}
|
|
6398
6500
|
}
|
|
@@ -6455,7 +6557,7 @@ function useSubscription(subscription, options) {
|
|
|
6455
6557
|
subscription !== ref.current.subscription ||
|
|
6456
6558
|
(options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
|
|
6457
6559
|
!(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
|
|
6458
|
-
!
|
|
6560
|
+
!equal.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
|
|
6459
6561
|
setResult({
|
|
6460
6562
|
loading: true,
|
|
6461
6563
|
data: void 0,
|
|
@@ -6542,7 +6644,6 @@ exports.HttpLink = HttpLink;
|
|
|
6542
6644
|
exports.InMemoryCache = InMemoryCache;
|
|
6543
6645
|
exports.MissingFieldError = MissingFieldError;
|
|
6544
6646
|
exports.ObservableQuery = ObservableQuery;
|
|
6545
|
-
exports.applyNextFetchPolicy = applyNextFetchPolicy;
|
|
6546
6647
|
exports.checkFetcher = checkFetcher;
|
|
6547
6648
|
exports.concat = concat;
|
|
6548
6649
|
exports.createHttpLink = createHttpLink;
|