@apollo/client 3.6.0-beta.10 → 3.6.0-beta.13
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 +187 -173
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/ApolloClient.d.ts +1 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +0 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +14 -13
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +2 -1
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +15 -14
- package/core/core.cjs.map +1 -1
- package/core/watchQueryOptions.d.ts +2 -1
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +4 -2
- package/react/hooks/hooks.cjs +154 -142
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/index.d.ts +1 -1
- package/react/hooks/index.d.ts.map +1 -1
- package/react/hooks/index.js +1 -1
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +2 -2
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +38 -24
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +34 -3
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +120 -99
- package/react/hooks/useQuery.js.map +1 -1
- package/react/types/types.d.ts +9 -13
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/utilities/graphql/transform.d.ts +2 -2
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +1 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/utilities.cjs +1 -1
- package/utilities/utilities.cjs.map +1 -1
- package/version.js +1 -1
- package/react/hooks/options.d.ts +0 -3
- package/react/hooks/options.d.ts.map +0 -1
- package/react/hooks/options.js +0 -20
- package/react/hooks/options.js.map +0 -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 equality = require('@wry/equality');
|
|
8
8
|
var zenObservableTs = require('zen-observable-ts');
|
|
9
9
|
require('symbol-observable');
|
|
10
10
|
var graphql = require('graphql');
|
|
@@ -13,8 +13,7 @@ var context = require('@wry/context');
|
|
|
13
13
|
var trie = require('@wry/trie');
|
|
14
14
|
var graphqlTag = require('graphql-tag');
|
|
15
15
|
var React = require('react');
|
|
16
|
-
|
|
17
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
16
|
+
var index_js = require('use-sync-external-store/shim/index.js');
|
|
18
17
|
|
|
19
18
|
function _interopNamespace(e) {
|
|
20
19
|
if (e && e.__esModule) return e;
|
|
@@ -28,7 +27,6 @@ function _interopNamespace(e) {
|
|
|
28
27
|
return Object.freeze(n);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
32
30
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
33
31
|
|
|
34
32
|
function maybe(thunk) {
|
|
@@ -542,7 +540,7 @@ function removeDirectivesFromDocument(directives, doc) {
|
|
|
542
540
|
return modifiedDoc;
|
|
543
541
|
}
|
|
544
542
|
var addTypenameToDocument = Object.assign(function (doc) {
|
|
545
|
-
return graphql.visit(
|
|
543
|
+
return graphql.visit(doc, {
|
|
546
544
|
SelectionSet: {
|
|
547
545
|
enter: function (node, _key, parent) {
|
|
548
546
|
if (parent &&
|
|
@@ -1294,7 +1292,7 @@ var concat = ApolloLink.concat;
|
|
|
1294
1292
|
|
|
1295
1293
|
var execute = ApolloLink.execute;
|
|
1296
1294
|
|
|
1297
|
-
var version = '3.6.0-beta.
|
|
1295
|
+
var version = '3.6.0-beta.13';
|
|
1298
1296
|
|
|
1299
1297
|
var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1300
1298
|
function parseAndCheckHttpResponse(operations) {
|
|
@@ -2162,7 +2160,7 @@ var Layer = (function (_super) {
|
|
|
2162
2160
|
}
|
|
2163
2161
|
else if (ownStoreObject !== parentStoreObject) {
|
|
2164
2162
|
Object.keys(ownStoreObject).forEach(function (storeFieldName) {
|
|
2165
|
-
if (!
|
|
2163
|
+
if (!equality.equal(ownStoreObject[storeFieldName], parentStoreObject[storeFieldName])) {
|
|
2166
2164
|
_this.group.dirty(dataId, storeFieldName);
|
|
2167
2165
|
}
|
|
2168
2166
|
});
|
|
@@ -2206,7 +2204,7 @@ var Stump = (function (_super) {
|
|
|
2206
2204
|
function storeObjectReconciler(existingObject, incomingObject, property) {
|
|
2207
2205
|
var existingValue = existingObject[property];
|
|
2208
2206
|
var incomingValue = incomingObject[property];
|
|
2209
|
-
return
|
|
2207
|
+
return equality.equal(existingValue, incomingValue) ? existingValue : incomingValue;
|
|
2210
2208
|
}
|
|
2211
2209
|
function supportsResultCaching(store) {
|
|
2212
2210
|
return !!(store instanceof EntityStore && store.group.caching);
|
|
@@ -3536,7 +3534,7 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
3536
3534
|
return;
|
|
3537
3535
|
if (isReference(existing))
|
|
3538
3536
|
return;
|
|
3539
|
-
if (
|
|
3537
|
+
if (equality.equal(existing, incoming))
|
|
3540
3538
|
return;
|
|
3541
3539
|
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
3542
3540
|
return;
|
|
@@ -3850,7 +3848,7 @@ var InMemoryCache = (function (_super) {
|
|
|
3850
3848
|
return;
|
|
3851
3849
|
}
|
|
3852
3850
|
}
|
|
3853
|
-
if (!lastDiff || !
|
|
3851
|
+
if (!lastDiff || !equality.equal(lastDiff.result, diff.result)) {
|
|
3854
3852
|
c.callback(c.lastDiff = diff, lastDiff);
|
|
3855
3853
|
}
|
|
3856
3854
|
};
|
|
@@ -3942,11 +3940,10 @@ var ObservableQuery = (function (_super) {
|
|
|
3942
3940
|
_this.observers = new Set();
|
|
3943
3941
|
_this.subscriptions = new Set();
|
|
3944
3942
|
_this.isTornDown = false;
|
|
3945
|
-
_this.options = options;
|
|
3943
|
+
_this.options = tslib.__assign({ initialFetchPolicy: options.fetchPolicy || "cache-first" }, options);
|
|
3946
3944
|
_this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
|
3947
3945
|
var opDef = getOperationDefinition(options.query);
|
|
3948
3946
|
_this.queryName = opDef && opDef.name && opDef.name.value;
|
|
3949
|
-
_this.initialFetchPolicy = options.fetchPolicy || "cache-first";
|
|
3950
3947
|
_this.queryManager = queryManager;
|
|
3951
3948
|
_this.queryInfo = queryInfo;
|
|
3952
3949
|
return _this;
|
|
@@ -3994,7 +3991,7 @@ var ObservableQuery = (function (_super) {
|
|
|
3994
3991
|
if (diff.complete || this.options.returnPartialData) {
|
|
3995
3992
|
result.data = diff.result;
|
|
3996
3993
|
}
|
|
3997
|
-
if (
|
|
3994
|
+
if (equality.equal(result.data, {})) {
|
|
3998
3995
|
result.data = void 0;
|
|
3999
3996
|
}
|
|
4000
3997
|
if (diff.complete) {
|
|
@@ -4025,13 +4022,13 @@ var ObservableQuery = (function (_super) {
|
|
|
4025
4022
|
return result;
|
|
4026
4023
|
};
|
|
4027
4024
|
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult) {
|
|
4028
|
-
return !this.last || !
|
|
4025
|
+
return !this.last || !equality.equal(this.last.result, newResult);
|
|
4029
4026
|
};
|
|
4030
4027
|
ObservableQuery.prototype.getLast = function (key, variablesMustMatch) {
|
|
4031
4028
|
var last = this.last;
|
|
4032
4029
|
if (last &&
|
|
4033
4030
|
last[key] &&
|
|
4034
|
-
(!variablesMustMatch ||
|
|
4031
|
+
(!variablesMustMatch || equality.equal(last.variables, this.variables))) {
|
|
4035
4032
|
return last[key];
|
|
4036
4033
|
}
|
|
4037
4034
|
};
|
|
@@ -4070,7 +4067,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4070
4067
|
__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 })?"));
|
|
4071
4068
|
}
|
|
4072
4069
|
}
|
|
4073
|
-
if (variables && !
|
|
4070
|
+
if (variables && !equality.equal(this.options.variables, variables)) {
|
|
4074
4071
|
reobserveOptions.variables = this.options.variables = tslib.__assign(tslib.__assign({}, this.options.variables), variables);
|
|
4075
4072
|
}
|
|
4076
4073
|
this.queryInfo.resetLastWrite();
|
|
@@ -4165,7 +4162,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4165
4162
|
return this.reobserve(newOptions);
|
|
4166
4163
|
};
|
|
4167
4164
|
ObservableQuery.prototype.setVariables = function (variables) {
|
|
4168
|
-
if (
|
|
4165
|
+
if (equality.equal(this.variables, variables)) {
|
|
4169
4166
|
return this.observers.size
|
|
4170
4167
|
? this.result()
|
|
4171
4168
|
: Promise.resolve();
|
|
@@ -4175,7 +4172,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4175
4172
|
return Promise.resolve();
|
|
4176
4173
|
}
|
|
4177
4174
|
return this.reobserve({
|
|
4178
|
-
fetchPolicy: this.initialFetchPolicy,
|
|
4175
|
+
fetchPolicy: this.options.initialFetchPolicy,
|
|
4179
4176
|
variables: variables,
|
|
4180
4177
|
}, exports.NetworkStatus.setVariables);
|
|
4181
4178
|
};
|
|
@@ -4208,19 +4205,18 @@ var ObservableQuery = (function (_super) {
|
|
|
4208
4205
|
this.updatePolling();
|
|
4209
4206
|
};
|
|
4210
4207
|
ObservableQuery.prototype.applyNextFetchPolicy = function (reason, options) {
|
|
4211
|
-
if (options === void 0) { options = this.options; }
|
|
4212
4208
|
if (options.nextFetchPolicy) {
|
|
4213
|
-
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
|
|
4209
|
+
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
|
|
4214
4210
|
if (typeof options.nextFetchPolicy === "function") {
|
|
4215
4211
|
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
4216
4212
|
reason: reason,
|
|
4217
4213
|
options: options,
|
|
4218
4214
|
observable: this,
|
|
4219
|
-
|
|
4215
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
4220
4216
|
});
|
|
4221
4217
|
}
|
|
4222
4218
|
else if (reason === "variables-changed") {
|
|
4223
|
-
options.fetchPolicy =
|
|
4219
|
+
options.fetchPolicy = initialFetchPolicy;
|
|
4224
4220
|
}
|
|
4225
4221
|
else {
|
|
4226
4222
|
options.fetchPolicy = options.nextFetchPolicy;
|
|
@@ -4290,16 +4286,18 @@ var ObservableQuery = (function (_super) {
|
|
|
4290
4286
|
newNetworkStatus === exports.NetworkStatus.fetchMore ||
|
|
4291
4287
|
newNetworkStatus === exports.NetworkStatus.poll;
|
|
4292
4288
|
var oldVariables = this.options.variables;
|
|
4289
|
+
var oldFetchPolicy = this.options.fetchPolicy;
|
|
4290
|
+
var mergedOptions = mergeOptions(this.options, newOptions || {});
|
|
4293
4291
|
var options = useDisposableConcast
|
|
4294
|
-
?
|
|
4295
|
-
: assign(this.options,
|
|
4292
|
+
? mergedOptions
|
|
4293
|
+
: assign(this.options, mergedOptions);
|
|
4296
4294
|
if (!useDisposableConcast) {
|
|
4297
4295
|
this.updatePolling();
|
|
4298
4296
|
if (newOptions &&
|
|
4299
4297
|
newOptions.variables &&
|
|
4300
|
-
!newOptions.
|
|
4301
|
-
!
|
|
4302
|
-
this.applyNextFetchPolicy("variables-changed");
|
|
4298
|
+
!equality.equal(newOptions.variables, oldVariables) &&
|
|
4299
|
+
(!newOptions.fetchPolicy || newOptions.fetchPolicy === oldFetchPolicy)) {
|
|
4300
|
+
this.applyNextFetchPolicy("variables-changed", options);
|
|
4303
4301
|
if (newNetworkStatus === void 0) {
|
|
4304
4302
|
newNetworkStatus = exports.NetworkStatus.setVariables;
|
|
4305
4303
|
}
|
|
@@ -4689,10 +4687,10 @@ var QueryInfo = (function () {
|
|
|
4689
4687
|
var networkStatus = query.networkStatus || exports.NetworkStatus.loading;
|
|
4690
4688
|
if (this.variables &&
|
|
4691
4689
|
this.networkStatus !== exports.NetworkStatus.loading &&
|
|
4692
|
-
!
|
|
4690
|
+
!equality.equal(this.variables, query.variables)) {
|
|
4693
4691
|
networkStatus = exports.NetworkStatus.setVariables;
|
|
4694
4692
|
}
|
|
4695
|
-
if (!
|
|
4693
|
+
if (!equality.equal(query.variables, this.variables)) {
|
|
4696
4694
|
this.lastDiff = void 0;
|
|
4697
4695
|
}
|
|
4698
4696
|
Object.assign(this, {
|
|
@@ -4718,7 +4716,7 @@ var QueryInfo = (function () {
|
|
|
4718
4716
|
QueryInfo.prototype.getDiff = function (variables) {
|
|
4719
4717
|
if (variables === void 0) { variables = this.variables; }
|
|
4720
4718
|
var options = this.getDiffOptions(variables);
|
|
4721
|
-
if (this.lastDiff &&
|
|
4719
|
+
if (this.lastDiff && equality.equal(options, this.lastDiff.options)) {
|
|
4722
4720
|
return this.lastDiff.diff;
|
|
4723
4721
|
}
|
|
4724
4722
|
this.updateWatch(this.variables = variables);
|
|
@@ -4752,7 +4750,7 @@ var QueryInfo = (function () {
|
|
|
4752
4750
|
var oldDiff = this.lastDiff && this.lastDiff.diff;
|
|
4753
4751
|
this.updateLastDiff(diff);
|
|
4754
4752
|
if (!this.dirty &&
|
|
4755
|
-
!
|
|
4753
|
+
!equality.equal(oldDiff && oldDiff.result, diff && diff.result)) {
|
|
4756
4754
|
this.dirty = true;
|
|
4757
4755
|
if (!this.notifyTimeout) {
|
|
4758
4756
|
this.notifyTimeout = setTimeout(function () { return _this.notify(); }, 0);
|
|
@@ -4827,7 +4825,7 @@ var QueryInfo = (function () {
|
|
|
4827
4825
|
}
|
|
4828
4826
|
var watchOptions = tslib.__assign(tslib.__assign({}, this.getDiffOptions(variables)), { watcher: this, callback: function (diff) { return _this.setDiff(diff); } });
|
|
4829
4827
|
if (!this.lastWatch ||
|
|
4830
|
-
!
|
|
4828
|
+
!equality.equal(watchOptions, this.lastWatch)) {
|
|
4831
4829
|
this.cancel();
|
|
4832
4830
|
this.cancel = this.cache.watch(this.lastWatch = watchOptions);
|
|
4833
4831
|
}
|
|
@@ -4839,8 +4837,8 @@ var QueryInfo = (function () {
|
|
|
4839
4837
|
var lastWrite = this.lastWrite;
|
|
4840
4838
|
return !(lastWrite &&
|
|
4841
4839
|
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
4842
|
-
|
|
4843
|
-
|
|
4840
|
+
equality.equal(variables, lastWrite.variables) &&
|
|
4841
|
+
equality.equal(result.data, lastWrite.result.data));
|
|
4844
4842
|
};
|
|
4845
4843
|
QueryInfo.prototype.markResult = function (result, options, cacheWriteBehavior) {
|
|
4846
4844
|
var _this = this;
|
|
@@ -5511,10 +5509,11 @@ var QueryManager = (function () {
|
|
|
5511
5509
|
var aqr = {
|
|
5512
5510
|
data: result.data,
|
|
5513
5511
|
loading: false,
|
|
5514
|
-
networkStatus:
|
|
5512
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
5515
5513
|
};
|
|
5516
5514
|
if (hasErrors && options.errorPolicy !== "ignore") {
|
|
5517
5515
|
aqr.errors = result.errors;
|
|
5516
|
+
aqr.networkStatus = exports.NetworkStatus.error;
|
|
5518
5517
|
}
|
|
5519
5518
|
return aqr;
|
|
5520
5519
|
}, function (networkError) {
|
|
@@ -5645,7 +5644,7 @@ var QueryManager = (function () {
|
|
|
5645
5644
|
var data = diff.result;
|
|
5646
5645
|
if (__DEV__ &&
|
|
5647
5646
|
!returnPartialData &&
|
|
5648
|
-
!
|
|
5647
|
+
!equality.equal(data, {})) {
|
|
5649
5648
|
logMissingFieldErrors(diff.missing);
|
|
5650
5649
|
}
|
|
5651
5650
|
var fromData = function (data) { return zenObservableTs.Observable.of(tslib.__assign({ data: data, loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus }, (diff.complete ? null : { partial: true }))); };
|
|
@@ -6108,26 +6107,9 @@ function verifyDocumentType(document, type) {
|
|
|
6108
6107
|
"".concat(requiredOperationName, ", but a ").concat(usedOperationName, " was used instead.")) : tsInvariant.invariant(operation.type === type, 34);
|
|
6109
6108
|
}
|
|
6110
6109
|
|
|
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
6110
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
6129
|
-
function useQuery(query,
|
|
6130
|
-
|
|
6111
|
+
function useQuery(query, options) {
|
|
6112
|
+
if (options === void 0) { options = Object.create(null); }
|
|
6131
6113
|
return useInternalState(useApolloClient(options.client), query).useQuery(options);
|
|
6132
6114
|
}
|
|
6133
6115
|
function useInternalState(client, query) {
|
|
@@ -6148,51 +6130,140 @@ var InternalState = (function () {
|
|
|
6148
6130
|
function InternalState(client, query) {
|
|
6149
6131
|
this.client = client;
|
|
6150
6132
|
this.query = query;
|
|
6133
|
+
this.ssrDisabledResult = maybeDeepFreeze({
|
|
6134
|
+
loading: true,
|
|
6135
|
+
data: void 0,
|
|
6136
|
+
error: void 0,
|
|
6137
|
+
networkStatus: exports.NetworkStatus.loading,
|
|
6138
|
+
});
|
|
6139
|
+
this.skipStandbyResult = maybeDeepFreeze({
|
|
6140
|
+
loading: false,
|
|
6141
|
+
data: void 0,
|
|
6142
|
+
error: void 0,
|
|
6143
|
+
networkStatus: exports.NetworkStatus.ready,
|
|
6144
|
+
});
|
|
6151
6145
|
this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
|
|
6152
6146
|
verifyDocumentType(query, exports.DocumentType.Query);
|
|
6153
6147
|
}
|
|
6154
6148
|
InternalState.prototype.forceUpdate = function () {
|
|
6155
6149
|
};
|
|
6156
6150
|
InternalState.prototype.useQuery = function (options) {
|
|
6151
|
+
var _this = this;
|
|
6152
|
+
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6157
6153
|
this.useOptions(options);
|
|
6158
6154
|
var obsQuery = this.useObservableQuery();
|
|
6159
|
-
|
|
6160
|
-
|
|
6155
|
+
var result = index_js.useSyncExternalStore(React.useCallback(function () {
|
|
6156
|
+
if (_this.renderPromises) {
|
|
6157
|
+
return function () { };
|
|
6158
|
+
}
|
|
6159
|
+
var onNext = function () {
|
|
6160
|
+
var previousResult = _this.result;
|
|
6161
|
+
var result = obsQuery.getCurrentResult();
|
|
6162
|
+
if (previousResult &&
|
|
6163
|
+
previousResult.loading === result.loading &&
|
|
6164
|
+
previousResult.networkStatus === result.networkStatus &&
|
|
6165
|
+
equality.equal(previousResult.data, result.data)) {
|
|
6166
|
+
return;
|
|
6167
|
+
}
|
|
6168
|
+
_this.setResult(result);
|
|
6169
|
+
};
|
|
6170
|
+
var onError = function (error) {
|
|
6171
|
+
var last = obsQuery["last"];
|
|
6172
|
+
subscription.unsubscribe();
|
|
6173
|
+
try {
|
|
6174
|
+
obsQuery.resetLastResults();
|
|
6175
|
+
subscription = obsQuery.subscribe(onNext, onError);
|
|
6176
|
+
}
|
|
6177
|
+
finally {
|
|
6178
|
+
obsQuery["last"] = last;
|
|
6179
|
+
}
|
|
6180
|
+
if (!hasOwnProperty.call(error, 'graphQLErrors')) {
|
|
6181
|
+
throw error;
|
|
6182
|
+
}
|
|
6183
|
+
var previousResult = _this.result;
|
|
6184
|
+
if (!previousResult ||
|
|
6185
|
+
(previousResult && previousResult.loading) ||
|
|
6186
|
+
!equality.equal(error, previousResult.error)) {
|
|
6187
|
+
_this.setResult({
|
|
6188
|
+
data: (previousResult && previousResult.data),
|
|
6189
|
+
error: error,
|
|
6190
|
+
loading: false,
|
|
6191
|
+
networkStatus: exports.NetworkStatus.error,
|
|
6192
|
+
});
|
|
6193
|
+
}
|
|
6194
|
+
};
|
|
6195
|
+
var subscription = obsQuery.subscribe(onNext, onError);
|
|
6196
|
+
return function () { return subscription.unsubscribe(); };
|
|
6197
|
+
}, [
|
|
6198
|
+
obsQuery,
|
|
6199
|
+
this.renderPromises,
|
|
6200
|
+
this.client.disableNetworkFetches,
|
|
6201
|
+
]), function () { return _this.getCurrentResult(); });
|
|
6161
6202
|
this.unsafeHandlePartialRefetch(result);
|
|
6162
6203
|
return this.toQueryResult(result);
|
|
6163
6204
|
};
|
|
6164
6205
|
InternalState.prototype.useOptions = function (options) {
|
|
6165
|
-
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6166
6206
|
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6167
|
-
if (!
|
|
6207
|
+
if (!equality.equal(watchQueryOptions, this.watchQueryOptions)) {
|
|
6168
6208
|
this.watchQueryOptions = watchQueryOptions;
|
|
6169
6209
|
}
|
|
6170
|
-
this.ssrDisabled = !!(options
|
|
6171
|
-
options.skip)
|
|
6172
|
-
this.onCompleted = options
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6210
|
+
this.ssrDisabled = !!(options.ssr === false ||
|
|
6211
|
+
options.skip);
|
|
6212
|
+
this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
|
|
6213
|
+
this.onError = options.onError || InternalState.prototype.onError;
|
|
6214
|
+
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
6215
|
+
this.queryHookOptions.ssr === false) {
|
|
6216
|
+
this.result = this.ssrDisabledResult;
|
|
6217
|
+
}
|
|
6218
|
+
else if (this.queryHookOptions.skip ||
|
|
6219
|
+
this.watchQueryOptions.fetchPolicy === 'standby') {
|
|
6220
|
+
this.result = this.skipStandbyResult;
|
|
6221
|
+
}
|
|
6222
|
+
else if (this.result === this.ssrDisabledResult ||
|
|
6223
|
+
this.result === this.skipStandbyResult) {
|
|
6224
|
+
this.result = void 0;
|
|
6225
|
+
}
|
|
6178
6226
|
};
|
|
6179
6227
|
InternalState.prototype.createWatchQueryOptions = function (_a) {
|
|
6180
|
-
var _b;
|
|
6181
6228
|
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
|
|
6184
|
-
|
|
6185
|
-
|
|
6229
|
+
var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; var defaultOptions = _a.defaultOptions, otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
|
|
6230
|
+
var toMerge = [];
|
|
6231
|
+
var globalDefaults = this.client.defaultOptions.watchQuery;
|
|
6232
|
+
if (globalDefaults)
|
|
6233
|
+
toMerge.push(globalDefaults);
|
|
6234
|
+
if (defaultOptions)
|
|
6235
|
+
toMerge.push(defaultOptions);
|
|
6236
|
+
var latestOptions = this.observable && this.observable.options;
|
|
6237
|
+
if (latestOptions && toMerge.length) {
|
|
6238
|
+
var defaults_1 = toMerge.reduce(mergeOptions, Object.create(null));
|
|
6239
|
+
toMerge.length = 1;
|
|
6240
|
+
toMerge[0] = defaults_1;
|
|
6241
|
+
Object.keys(defaults_1).forEach(function (defaultOptionName) {
|
|
6242
|
+
var currentOptionValue = latestOptions[defaultOptionName];
|
|
6243
|
+
if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
|
|
6244
|
+
!equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
|
|
6245
|
+
defaults_1[defaultOptionName] = defaultOptionName === "variables"
|
|
6246
|
+
? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
|
|
6247
|
+
}
|
|
6248
|
+
});
|
|
6186
6249
|
}
|
|
6187
|
-
|
|
6250
|
+
toMerge.push(otherOptions);
|
|
6251
|
+
var merged = toMerge.reduce(mergeOptions, Object.create(null));
|
|
6252
|
+
var watchQueryOptions = Object.assign(merged, { query: this.query });
|
|
6253
|
+
if (this.renderPromises &&
|
|
6188
6254
|
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
6189
6255
|
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
6190
6256
|
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6191
6257
|
}
|
|
6192
6258
|
else if (!watchQueryOptions.fetchPolicy) {
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6259
|
+
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6260
|
+
}
|
|
6261
|
+
if (skip) {
|
|
6262
|
+
var _b = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? watchQueryOptions.fetchPolicy : _b;
|
|
6263
|
+
Object.assign(watchQueryOptions, {
|
|
6264
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
6265
|
+
fetchPolicy: 'standby',
|
|
6266
|
+
});
|
|
6196
6267
|
}
|
|
6197
6268
|
if (!watchQueryOptions.variables) {
|
|
6198
6269
|
watchQueryOptions.variables = {};
|
|
@@ -6210,6 +6281,7 @@ var InternalState = (function () {
|
|
|
6210
6281
|
|| this.client.watchQuery(this.watchQueryOptions);
|
|
6211
6282
|
this.obsQueryFields = React.useMemo(function () { return ({
|
|
6212
6283
|
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6284
|
+
reobserve: obsQuery.reobserve.bind(obsQuery),
|
|
6213
6285
|
fetchMore: obsQuery.fetchMore.bind(obsQuery),
|
|
6214
6286
|
updateQuery: obsQuery.updateQuery.bind(obsQuery),
|
|
6215
6287
|
startPolling: obsQuery.startPolling.bind(obsQuery),
|
|
@@ -6255,56 +6327,6 @@ var InternalState = (function () {
|
|
|
6255
6327
|
}, [obsQuery, this.watchQueryOptions]);
|
|
6256
6328
|
return obsQuery;
|
|
6257
6329
|
};
|
|
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
6330
|
InternalState.prototype.setResult = function (nextResult) {
|
|
6309
6331
|
var previousResult = this.result;
|
|
6310
6332
|
if (previousResult && previousResult.data) {
|
|
@@ -6325,30 +6347,10 @@ var InternalState = (function () {
|
|
|
6325
6347
|
}
|
|
6326
6348
|
};
|
|
6327
6349
|
InternalState.prototype.getCurrentResult = function () {
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
result = this.result = this.observable.getCurrentResult();
|
|
6331
|
-
this.handleErrorOrCompleted(result);
|
|
6332
|
-
}
|
|
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
|
-
};
|
|
6350
|
+
if (!this.result) {
|
|
6351
|
+
this.handleErrorOrCompleted(this.result = this.observable.getCurrentResult());
|
|
6341
6352
|
}
|
|
6342
|
-
|
|
6343
|
-
this.queryHookOptions.fetchPolicy === 'standby') {
|
|
6344
|
-
result = {
|
|
6345
|
-
loading: false,
|
|
6346
|
-
data: void 0,
|
|
6347
|
-
error: void 0,
|
|
6348
|
-
networkStatus: exports.NetworkStatus.ready,
|
|
6349
|
-
};
|
|
6350
|
-
}
|
|
6351
|
-
return result;
|
|
6353
|
+
return this.result;
|
|
6352
6354
|
};
|
|
6353
6355
|
InternalState.prototype.toQueryResult = function (result) {
|
|
6354
6356
|
var queryResult = this.toQueryResultCache.get(result);
|
|
@@ -6379,31 +6381,34 @@ var InternalState = (function () {
|
|
|
6379
6381
|
|
|
6380
6382
|
var EAGER_METHODS = [
|
|
6381
6383
|
'refetch',
|
|
6384
|
+
'reobserve',
|
|
6382
6385
|
'fetchMore',
|
|
6383
6386
|
'updateQuery',
|
|
6384
6387
|
'startPolling',
|
|
6385
6388
|
'subscribeToMore',
|
|
6386
6389
|
];
|
|
6387
|
-
function useLazyQuery(query,
|
|
6388
|
-
var
|
|
6389
|
-
var
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
}
|
|
6390
|
+
function useLazyQuery(query, options) {
|
|
6391
|
+
var internalState = useInternalState(useApolloClient(options && options.client), query);
|
|
6392
|
+
var execOptionsRef = React.useRef();
|
|
6393
|
+
var defaultOptions = internalState.client.defaultOptions.watchQuery;
|
|
6394
|
+
var initialFetchPolicy = (options && options.fetchPolicy) ||
|
|
6395
|
+
(execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
|
|
6396
|
+
(defaultOptions && defaultOptions.fetchPolicy) ||
|
|
6397
|
+
"cache-first";
|
|
6398
|
+
var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
|
|
6399
|
+
var result = Object.assign(useQueryResult, {
|
|
6400
|
+
called: !!execOptionsRef.current,
|
|
6401
|
+
});
|
|
6396
6402
|
var eagerMethods = React.useMemo(function () {
|
|
6397
6403
|
var eagerMethods = {};
|
|
6398
6404
|
var _loop_1 = function (key) {
|
|
6399
6405
|
var method = result[key];
|
|
6400
6406
|
eagerMethods[key] = function () {
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6407
|
+
if (!execOptionsRef.current) {
|
|
6408
|
+
execOptionsRef.current = Object.create(null);
|
|
6409
|
+
internalState.forceUpdate();
|
|
6404
6410
|
}
|
|
6405
|
-
|
|
6406
|
-
return method.apply(void 0, args);
|
|
6411
|
+
return method.apply(this, arguments);
|
|
6407
6412
|
};
|
|
6408
6413
|
};
|
|
6409
6414
|
for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
|
|
@@ -6412,15 +6417,24 @@ function useLazyQuery(query, optionsOrFunction) {
|
|
|
6412
6417
|
}
|
|
6413
6418
|
return eagerMethods;
|
|
6414
6419
|
}, []);
|
|
6415
|
-
result.error = result.error || void 0;
|
|
6416
6420
|
Object.assign(result, eagerMethods);
|
|
6417
6421
|
var execute = React.useCallback(function (executeOptions) {
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6422
|
+
var promise = result.reobserve(execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
6423
|
+
fetchPolicy: initialFetchPolicy,
|
|
6424
|
+
}).then(function (apolloQueryResult) {
|
|
6425
|
+
apolloQueryResult = apolloQueryResult || internalState["getCurrentResult"]();
|
|
6426
|
+
if (apolloQueryResult.error ||
|
|
6427
|
+
isNonEmptyArray(apolloQueryResult.errors)) {
|
|
6428
|
+
var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
|
|
6429
|
+
if (errorPolicy === "none") {
|
|
6430
|
+
throw apolloQueryResult.error || new ApolloError({
|
|
6431
|
+
graphQLErrors: apolloQueryResult.errors,
|
|
6432
|
+
});
|
|
6433
|
+
}
|
|
6434
|
+
}
|
|
6435
|
+
return internalState.toQueryResult(apolloQueryResult);
|
|
6436
|
+
}).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
6437
|
+
internalState.forceUpdate();
|
|
6424
6438
|
promise.catch(function () { });
|
|
6425
6439
|
return promise;
|
|
6426
6440
|
}, []);
|
|
@@ -6476,7 +6490,7 @@ function useMutation(mutation, options) {
|
|
|
6476
6490
|
error: error,
|
|
6477
6491
|
client: client,
|
|
6478
6492
|
};
|
|
6479
|
-
if (ref.current.isMounted && !
|
|
6493
|
+
if (ref.current.isMounted && !equality.equal(ref.current.result, result_1)) {
|
|
6480
6494
|
setResult(ref.current.result = result_1);
|
|
6481
6495
|
}
|
|
6482
6496
|
}
|
|
@@ -6494,7 +6508,7 @@ function useMutation(mutation, options) {
|
|
|
6494
6508
|
called: true,
|
|
6495
6509
|
client: client,
|
|
6496
6510
|
};
|
|
6497
|
-
if (!
|
|
6511
|
+
if (!equality.equal(ref.current.result, result_2)) {
|
|
6498
6512
|
setResult(ref.current.result = result_2);
|
|
6499
6513
|
}
|
|
6500
6514
|
}
|
|
@@ -6557,7 +6571,7 @@ function useSubscription(subscription, options) {
|
|
|
6557
6571
|
subscription !== ref.current.subscription ||
|
|
6558
6572
|
(options === null || options === void 0 ? void 0 : options.fetchPolicy) !== ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
|
|
6559
6573
|
!(options === null || options === void 0 ? void 0 : options.skip) !== !((_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.skip) ||
|
|
6560
|
-
!
|
|
6574
|
+
!equality.equal(options === null || options === void 0 ? void 0 : options.variables, (_d = ref.current.options) === null || _d === void 0 ? void 0 : _d.variables))) {
|
|
6561
6575
|
setResult({
|
|
6562
6576
|
loading: true,
|
|
6563
6577
|
data: void 0,
|