@apollo/client 3.7.0-alpha.1 → 3.7.0-alpha.4
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 +132 -88
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs.native.js +2289 -0
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +4 -2
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +4 -3
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +8 -5
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +2142 -0
- package/errors/errors.cjs.native.js +48 -0
- package/invariantErrorCodes.js +1 -1
- package/link/batch/batch.cjs.native.js +161 -0
- package/link/batch-http/batch-http.cjs.native.js +127 -0
- package/link/context/context.cjs.native.js +38 -0
- package/link/core/core.cjs.native.js +121 -0
- package/link/error/error.cjs.native.js +90 -0
- package/link/http/http.cjs.native.js +320 -0
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
- package/link/retry/retry.cjs.native.js +170 -0
- package/link/schema/schema.cjs.native.js +56 -0
- package/link/subscriptions/subscriptions.cjs.native.js +45 -0
- package/link/utils/utils.cjs.native.js +115 -0
- package/link/ws/ws.cjs.native.js +28 -0
- package/main.cjs.native.js +16 -0
- package/package.json +7 -8
- package/react/components/components.cjs.native.js +79 -0
- package/react/context/context.cjs.native.js +67 -0
- package/react/hoc/hoc.cjs.native.js +325 -0
- package/react/hooks/hooks.cjs +133 -82
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +594 -0
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +7 -22
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +5 -1
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +45 -38
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.d.ts +4 -0
- package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
- package/react/hooks/useSyncExternalStore.js +48 -0
- package/react/hooks/useSyncExternalStore.js.map +1 -0
- package/react/parser/parser.cjs.native.js +103 -0
- package/react/react.cjs.native.js +22 -0
- package/react/ssr/ssr.cjs.native.js +150 -0
- package/testing/core/core.cjs.native.js +288 -0
- package/testing/testing.cjs.native.js +58 -0
- package/utilities/common/canUse.d.ts +2 -0
- package/utilities/common/canUse.d.ts.map +1 -1
- package/utilities/common/canUse.js +6 -2
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +1 -1
- package/utilities/common/mergeOptions.d.ts.map +1 -1
- package/utilities/common/mergeOptions.js +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/globals/globals.cjs.native.js +56 -0
- package/utilities/observables/Concast.d.ts +5 -3
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +22 -21
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/utilities.cjs +30 -24
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +1280 -0
- package/version.js +1 -1
package/apollo-client.cjs
CHANGED
|
@@ -13,7 +13,6 @@ 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
|
-
var index_js = require('use-sync-external-store/shim/index.js');
|
|
17
16
|
|
|
18
17
|
function _interopNamespace(e) {
|
|
19
18
|
if (e && e.__esModule) return e;
|
|
@@ -899,11 +898,14 @@ function asyncMap(observable, mapFn, catchFn) {
|
|
|
899
898
|
});
|
|
900
899
|
}
|
|
901
900
|
|
|
902
|
-
var canUseWeakMap = typeof WeakMap === 'function' &&
|
|
903
|
-
navigator.product
|
|
901
|
+
var canUseWeakMap = typeof WeakMap === 'function' &&
|
|
902
|
+
maybe(function () { return navigator.product; }) !== 'ReactNative';
|
|
904
903
|
var canUseWeakSet = typeof WeakSet === 'function';
|
|
905
904
|
var canUseSymbol = typeof Symbol === 'function' &&
|
|
906
905
|
typeof Symbol.for === 'function';
|
|
906
|
+
var canUseDOM = typeof maybe(function () { return window.document.createElement; }) === "function";
|
|
907
|
+
var usingJSDOM = maybe(function () { return navigator.userAgent.indexOf("jsdom") >= 0; }) || false;
|
|
908
|
+
var canUseLayoutEffect = canUseDOM && !usingJSDOM;
|
|
907
909
|
|
|
908
910
|
function fixObservableSubclass(subclass) {
|
|
909
911
|
function set(key) {
|
|
@@ -927,7 +929,6 @@ var Concast = (function (_super) {
|
|
|
927
929
|
return function () { return _this.removeObserver(observer); };
|
|
928
930
|
}) || this;
|
|
929
931
|
_this.observers = new Set();
|
|
930
|
-
_this.addCount = 0;
|
|
931
932
|
_this.promise = new Promise(function (resolve, reject) {
|
|
932
933
|
_this.resolve = resolve;
|
|
933
934
|
_this.reject = reject;
|
|
@@ -936,6 +937,7 @@ var Concast = (function (_super) {
|
|
|
936
937
|
next: function (result) {
|
|
937
938
|
if (_this.sub !== null) {
|
|
938
939
|
_this.latest = ["next", result];
|
|
940
|
+
_this.notify("next", result);
|
|
939
941
|
iterateObserversSafely(_this.observers, "next", result);
|
|
940
942
|
}
|
|
941
943
|
},
|
|
@@ -947,13 +949,17 @@ var Concast = (function (_super) {
|
|
|
947
949
|
_this.sub = null;
|
|
948
950
|
_this.latest = ["error", error];
|
|
949
951
|
_this.reject(error);
|
|
952
|
+
_this.notify("error", error);
|
|
950
953
|
iterateObserversSafely(_this.observers, "error", error);
|
|
951
954
|
}
|
|
952
955
|
},
|
|
953
956
|
complete: function () {
|
|
954
|
-
|
|
957
|
+
var sub = _this.sub;
|
|
958
|
+
if (sub !== null) {
|
|
955
959
|
var value = _this.sources.shift();
|
|
956
960
|
if (!value) {
|
|
961
|
+
if (sub)
|
|
962
|
+
setTimeout(function () { return sub.unsubscribe(); });
|
|
957
963
|
_this.sub = null;
|
|
958
964
|
if (_this.latest &&
|
|
959
965
|
_this.latest[0] === "next") {
|
|
@@ -962,6 +968,7 @@ var Concast = (function (_super) {
|
|
|
962
968
|
else {
|
|
963
969
|
_this.resolve();
|
|
964
970
|
}
|
|
971
|
+
_this.notify("complete");
|
|
965
972
|
iterateObserversSafely(_this.observers, "complete");
|
|
966
973
|
}
|
|
967
974
|
else if (isPromiseLike(value)) {
|
|
@@ -973,6 +980,7 @@ var Concast = (function (_super) {
|
|
|
973
980
|
}
|
|
974
981
|
},
|
|
975
982
|
};
|
|
983
|
+
_this.nextResultListeners = new Set();
|
|
976
984
|
_this.cancel = function (reason) {
|
|
977
985
|
_this.reject(reason);
|
|
978
986
|
_this.sources = [];
|
|
@@ -1014,34 +1022,29 @@ var Concast = (function (_super) {
|
|
|
1014
1022
|
if (!this.observers.has(observer)) {
|
|
1015
1023
|
this.deliverLastMessage(observer);
|
|
1016
1024
|
this.observers.add(observer);
|
|
1017
|
-
++this.addCount;
|
|
1018
1025
|
}
|
|
1019
1026
|
};
|
|
1020
|
-
Concast.prototype.removeObserver = function (observer
|
|
1027
|
+
Concast.prototype.removeObserver = function (observer) {
|
|
1021
1028
|
if (this.observers.delete(observer) &&
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
this.handlers.error(new Error("Observable cancelled prematurely"));
|
|
1029
|
+
this.observers.size < 1) {
|
|
1030
|
+
this.handlers.complete();
|
|
1025
1031
|
}
|
|
1026
1032
|
};
|
|
1027
|
-
Concast.prototype.
|
|
1028
|
-
var
|
|
1033
|
+
Concast.prototype.notify = function (method, arg) {
|
|
1034
|
+
var nextResultListeners = this.nextResultListeners;
|
|
1035
|
+
if (nextResultListeners.size) {
|
|
1036
|
+
this.nextResultListeners = new Set;
|
|
1037
|
+
nextResultListeners.forEach(function (listener) { return listener(method, arg); });
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
Concast.prototype.beforeNext = function (callback) {
|
|
1029
1041
|
var called = false;
|
|
1030
|
-
|
|
1042
|
+
this.nextResultListeners.add(function (method, arg) {
|
|
1031
1043
|
if (!called) {
|
|
1032
1044
|
called = true;
|
|
1033
|
-
|
|
1034
|
-
callback();
|
|
1045
|
+
callback(method, arg);
|
|
1035
1046
|
}
|
|
1036
|
-
};
|
|
1037
|
-
var observer = {
|
|
1038
|
-
next: once,
|
|
1039
|
-
error: once,
|
|
1040
|
-
complete: once,
|
|
1041
|
-
};
|
|
1042
|
-
var count = this.addCount;
|
|
1043
|
-
this.addObserver(observer);
|
|
1044
|
-
this.addCount = count;
|
|
1047
|
+
});
|
|
1045
1048
|
};
|
|
1046
1049
|
return Concast;
|
|
1047
1050
|
}(zenObservableTs.Observable));
|
|
@@ -1090,7 +1093,7 @@ function stringifyForDisplay(value) {
|
|
|
1090
1093
|
|
|
1091
1094
|
function mergeOptions(defaults, options) {
|
|
1092
1095
|
return compact(defaults, options, options.variables && {
|
|
1093
|
-
variables: tslib.__assign(tslib.__assign({}, defaults.variables), options.variables),
|
|
1096
|
+
variables: tslib.__assign(tslib.__assign({}, (defaults && defaults.variables)), options.variables),
|
|
1094
1097
|
});
|
|
1095
1098
|
}
|
|
1096
1099
|
|
|
@@ -1298,7 +1301,7 @@ var concat = ApolloLink.concat;
|
|
|
1298
1301
|
|
|
1299
1302
|
var execute = ApolloLink.execute;
|
|
1300
1303
|
|
|
1301
|
-
var version = '3.7.0-alpha.
|
|
1304
|
+
var version = '3.7.0-alpha.4';
|
|
1302
1305
|
|
|
1303
1306
|
var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1304
1307
|
function parseAndCheckHttpResponse(operations) {
|
|
@@ -3948,7 +3951,9 @@ var ObservableQuery = (function (_super) {
|
|
|
3948
3951
|
_this.queryInfo = queryInfo;
|
|
3949
3952
|
_this.queryManager = queryManager;
|
|
3950
3953
|
_this.isTornDown = false;
|
|
3951
|
-
|
|
3954
|
+
var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
|
|
3955
|
+
var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e, _f = options.initialFetchPolicy, initialFetchPolicy = _f === void 0 ? (fetchPolicy === "standby" ? defaultFetchPolicy : fetchPolicy) : _f;
|
|
3956
|
+
_this.options = tslib.__assign(tslib.__assign({}, options), { initialFetchPolicy: initialFetchPolicy, fetchPolicy: fetchPolicy });
|
|
3952
3957
|
_this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
|
3953
3958
|
var opDef = getOperationDefinition(_this.query);
|
|
3954
3959
|
_this.queryName = opDef && opDef.name && opDef.name.value;
|
|
@@ -4328,7 +4333,7 @@ var ObservableQuery = (function (_super) {
|
|
|
4328
4333
|
};
|
|
4329
4334
|
if (!useDisposableConcast) {
|
|
4330
4335
|
if (this.concast && this.observer) {
|
|
4331
|
-
this.concast.removeObserver(this.observer
|
|
4336
|
+
this.concast.removeObserver(this.observer);
|
|
4332
4337
|
}
|
|
4333
4338
|
this.concast = concast;
|
|
4334
4339
|
this.observer = observer;
|
|
@@ -5473,7 +5478,7 @@ var QueryManager = (function () {
|
|
|
5473
5478
|
execute(link, operation)
|
|
5474
5479
|
]);
|
|
5475
5480
|
byVariables_1.set(varJson_1, observable = concast);
|
|
5476
|
-
concast.
|
|
5481
|
+
concast.beforeNext(function () {
|
|
5477
5482
|
if (byVariables_1.delete(varJson_1) &&
|
|
5478
5483
|
byVariables_1.size < 1) {
|
|
5479
5484
|
inFlightLinkObservables_1.delete(serverQuery);
|
|
@@ -5508,6 +5513,7 @@ var QueryManager = (function () {
|
|
|
5508
5513
|
};
|
|
5509
5514
|
QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
|
|
5510
5515
|
var requestId = queryInfo.lastRequestId = this.generateRequestId();
|
|
5516
|
+
options = cloneDeep(options);
|
|
5511
5517
|
return asyncMap(this.getObservableFromLink(queryInfo.document, options.context, options.variables), function (result) {
|
|
5512
5518
|
var hasErrors = isNonEmptyArray(result.errors);
|
|
5513
5519
|
if (requestId >= queryInfo.lastRequestId) {
|
|
@@ -5566,7 +5572,7 @@ var QueryManager = (function () {
|
|
|
5566
5572
|
var concast = new Concast(this.transform(normalized.query).hasClientExports
|
|
5567
5573
|
? this.localState.addExportedVariables(normalized.query, normalized.variables, normalized.context).then(fromVariables)
|
|
5568
5574
|
: fromVariables(normalized.variables));
|
|
5569
|
-
concast.
|
|
5575
|
+
concast.beforeNext(function () {
|
|
5570
5576
|
_this.fetchCancelFns.delete(queryId);
|
|
5571
5577
|
if (queryInfo.observableQuery) {
|
|
5572
5578
|
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
@@ -6034,6 +6040,51 @@ function useApolloClient(override) {
|
|
|
6034
6040
|
return client;
|
|
6035
6041
|
}
|
|
6036
6042
|
|
|
6043
|
+
var didWarnUncachedGetSnapshot = false;
|
|
6044
|
+
var uSESKey = "useSyncExternalStore";
|
|
6045
|
+
var realHook = React__namespace[uSESKey];
|
|
6046
|
+
var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
|
|
6047
|
+
var value = getSnapshot();
|
|
6048
|
+
if (__DEV__ &&
|
|
6049
|
+
!didWarnUncachedGetSnapshot &&
|
|
6050
|
+
value !== getSnapshot()) {
|
|
6051
|
+
didWarnUncachedGetSnapshot = true;
|
|
6052
|
+
__DEV__ && tsInvariant.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
6053
|
+
}
|
|
6054
|
+
var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
|
|
6055
|
+
if (canUseLayoutEffect) {
|
|
6056
|
+
React__namespace.useLayoutEffect(function () {
|
|
6057
|
+
Object.assign(inst, { value: value, getSnapshot: getSnapshot });
|
|
6058
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
6059
|
+
forceUpdate({ inst: inst });
|
|
6060
|
+
}
|
|
6061
|
+
}, [subscribe, value, getSnapshot]);
|
|
6062
|
+
}
|
|
6063
|
+
else {
|
|
6064
|
+
Object.assign(inst, { value: value, getSnapshot: getSnapshot });
|
|
6065
|
+
}
|
|
6066
|
+
React__namespace.useEffect(function () {
|
|
6067
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
6068
|
+
forceUpdate({ inst: inst });
|
|
6069
|
+
}
|
|
6070
|
+
return subscribe(function handleStoreChange() {
|
|
6071
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
6072
|
+
forceUpdate({ inst: inst });
|
|
6073
|
+
}
|
|
6074
|
+
});
|
|
6075
|
+
}, [subscribe]);
|
|
6076
|
+
return value;
|
|
6077
|
+
});
|
|
6078
|
+
function checkIfSnapshotChanged(_a) {
|
|
6079
|
+
var value = _a.value, getSnapshot = _a.getSnapshot;
|
|
6080
|
+
try {
|
|
6081
|
+
return value !== getSnapshot();
|
|
6082
|
+
}
|
|
6083
|
+
catch (_b) {
|
|
6084
|
+
return true;
|
|
6085
|
+
}
|
|
6086
|
+
}
|
|
6087
|
+
|
|
6037
6088
|
exports.DocumentType = void 0;
|
|
6038
6089
|
(function (DocumentType) {
|
|
6039
6090
|
DocumentType[DocumentType["Query"] = 0] = "Query";
|
|
@@ -6150,6 +6201,8 @@ var InternalState = (function () {
|
|
|
6150
6201
|
function InternalState(client, query) {
|
|
6151
6202
|
this.client = client;
|
|
6152
6203
|
this.query = query;
|
|
6204
|
+
this.asyncResolveFns = new Set();
|
|
6205
|
+
this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
|
|
6153
6206
|
this.ssrDisabledResult = maybeDeepFreeze({
|
|
6154
6207
|
loading: true,
|
|
6155
6208
|
data: void 0,
|
|
@@ -6166,13 +6219,22 @@ var InternalState = (function () {
|
|
|
6166
6219
|
verifyDocumentType(query, exports.DocumentType.Query);
|
|
6167
6220
|
}
|
|
6168
6221
|
InternalState.prototype.forceUpdate = function () {
|
|
6222
|
+
__DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
|
|
6223
|
+
};
|
|
6224
|
+
InternalState.prototype.asyncUpdate = function () {
|
|
6225
|
+
var _this = this;
|
|
6226
|
+
return new Promise(function (resolve) {
|
|
6227
|
+
_this.asyncResolveFns.add(resolve);
|
|
6228
|
+
_this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
|
|
6229
|
+
_this.forceUpdate();
|
|
6230
|
+
});
|
|
6169
6231
|
};
|
|
6170
6232
|
InternalState.prototype.useQuery = function (options) {
|
|
6171
6233
|
var _this = this;
|
|
6172
6234
|
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6173
6235
|
this.useOptions(options);
|
|
6174
6236
|
var obsQuery = this.useObservableQuery();
|
|
6175
|
-
var result =
|
|
6237
|
+
var result = useSyncExternalStore(React.useCallback(function () {
|
|
6176
6238
|
if (_this.renderPromises) {
|
|
6177
6239
|
return function () { };
|
|
6178
6240
|
}
|
|
@@ -6220,15 +6282,22 @@ var InternalState = (function () {
|
|
|
6220
6282
|
this.client.disableNetworkFetches,
|
|
6221
6283
|
]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
|
|
6222
6284
|
this.unsafeHandlePartialRefetch(result);
|
|
6223
|
-
|
|
6285
|
+
var queryResult = this.toQueryResult(result);
|
|
6286
|
+
if (!queryResult.loading && this.asyncResolveFns.size) {
|
|
6287
|
+
this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
|
|
6288
|
+
this.asyncResolveFns.clear();
|
|
6289
|
+
}
|
|
6290
|
+
return queryResult;
|
|
6224
6291
|
};
|
|
6225
6292
|
InternalState.prototype.useOptions = function (options) {
|
|
6226
6293
|
var _a;
|
|
6227
6294
|
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6228
6295
|
var currentWatchQueryOptions = this.watchQueryOptions;
|
|
6229
|
-
if (
|
|
6296
|
+
if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
|
|
6297
|
+
!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
6230
6298
|
this.watchQueryOptions = watchQueryOptions;
|
|
6231
6299
|
if (currentWatchQueryOptions && this.observable) {
|
|
6300
|
+
this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
|
|
6232
6301
|
this.observable.reobserve(watchQueryOptions);
|
|
6233
6302
|
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
6234
6303
|
this.result = void 0;
|
|
@@ -6237,7 +6306,8 @@ var InternalState = (function () {
|
|
|
6237
6306
|
this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
|
|
6238
6307
|
this.onError = options.onError || InternalState.prototype.onError;
|
|
6239
6308
|
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
6240
|
-
this.queryHookOptions.ssr === false
|
|
6309
|
+
this.queryHookOptions.ssr === false &&
|
|
6310
|
+
!this.queryHookOptions.skip) {
|
|
6241
6311
|
this.result = this.ssrDisabledResult;
|
|
6242
6312
|
}
|
|
6243
6313
|
else if (this.queryHookOptions.skip ||
|
|
@@ -6250,51 +6320,38 @@ var InternalState = (function () {
|
|
|
6250
6320
|
}
|
|
6251
6321
|
};
|
|
6252
6322
|
InternalState.prototype.createWatchQueryOptions = function (_a) {
|
|
6323
|
+
var _b;
|
|
6253
6324
|
if (_a === void 0) { _a = {}; }
|
|
6254
|
-
var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName;
|
|
6255
|
-
var
|
|
6256
|
-
var globalDefaults = this.client.defaultOptions.watchQuery;
|
|
6257
|
-
if (globalDefaults)
|
|
6258
|
-
toMerge.push(globalDefaults);
|
|
6259
|
-
if (defaultOptions)
|
|
6260
|
-
toMerge.push(defaultOptions);
|
|
6261
|
-
var latestOptions = this.observable && this.observable.options;
|
|
6262
|
-
if (latestOptions && toMerge.length) {
|
|
6263
|
-
var defaults_1 = toMerge.reduce(mergeOptions, Object.create(null));
|
|
6264
|
-
toMerge.length = 1;
|
|
6265
|
-
toMerge[0] = defaults_1;
|
|
6266
|
-
Object.keys(defaults_1).forEach(function (defaultOptionName) {
|
|
6267
|
-
var currentOptionValue = latestOptions[defaultOptionName];
|
|
6268
|
-
if (hasOwnProperty.call(latestOptions, defaultOptionName) &&
|
|
6269
|
-
!equality.equal(defaults_1[defaultOptionName], currentOptionValue)) {
|
|
6270
|
-
defaults_1[defaultOptionName] = defaultOptionName === "variables"
|
|
6271
|
-
? tslib.__assign(tslib.__assign({}, defaults_1.variables), currentOptionValue) : currentOptionValue;
|
|
6272
|
-
}
|
|
6273
|
-
});
|
|
6274
|
-
}
|
|
6275
|
-
toMerge.push(otherOptions);
|
|
6276
|
-
var merged = toMerge.reduce(mergeOptions, Object.create(null));
|
|
6277
|
-
var watchQueryOptions = Object.assign(merged, { query: this.query });
|
|
6325
|
+
var skip = _a.skip; _a.ssr; _a.onCompleted; _a.onError; _a.displayName; _a.defaultOptions; var otherOptions = tslib.__rest(_a, ["skip", "ssr", "onCompleted", "onError", "displayName", "defaultOptions"]);
|
|
6326
|
+
var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
|
|
6278
6327
|
if (this.renderPromises &&
|
|
6279
6328
|
(watchQueryOptions.fetchPolicy === 'network-only' ||
|
|
6280
6329
|
watchQueryOptions.fetchPolicy === 'cache-and-network')) {
|
|
6281
6330
|
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
6282
6331
|
}
|
|
6283
|
-
|
|
6284
|
-
watchQueryOptions.
|
|
6332
|
+
if (!watchQueryOptions.variables) {
|
|
6333
|
+
watchQueryOptions.variables = {};
|
|
6285
6334
|
}
|
|
6286
6335
|
if (skip) {
|
|
6287
|
-
var
|
|
6336
|
+
var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
|
|
6288
6337
|
Object.assign(watchQueryOptions, {
|
|
6289
6338
|
initialFetchPolicy: initialFetchPolicy,
|
|
6290
6339
|
fetchPolicy: 'standby',
|
|
6291
6340
|
});
|
|
6292
6341
|
}
|
|
6293
|
-
if (!watchQueryOptions.
|
|
6294
|
-
watchQueryOptions.
|
|
6342
|
+
else if (!watchQueryOptions.fetchPolicy) {
|
|
6343
|
+
watchQueryOptions.fetchPolicy =
|
|
6344
|
+
((_b = this.observable) === null || _b === void 0 ? void 0 : _b.options.initialFetchPolicy) ||
|
|
6345
|
+
this.getDefaultFetchPolicy();
|
|
6295
6346
|
}
|
|
6296
6347
|
return watchQueryOptions;
|
|
6297
6348
|
};
|
|
6349
|
+
InternalState.prototype.getDefaultFetchPolicy = function () {
|
|
6350
|
+
var _a, _b;
|
|
6351
|
+
return (((_a = this.queryHookOptions.defaultOptions) === null || _a === void 0 ? void 0 : _a.fetchPolicy) ||
|
|
6352
|
+
((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
|
|
6353
|
+
"cache-first");
|
|
6354
|
+
};
|
|
6298
6355
|
InternalState.prototype.onCompleted = function (data) { };
|
|
6299
6356
|
InternalState.prototype.onError = function (error) { };
|
|
6300
6357
|
InternalState.prototype.useObservableQuery = function () {
|
|
@@ -6302,7 +6359,7 @@ var InternalState = (function () {
|
|
|
6302
6359
|
this.renderPromises
|
|
6303
6360
|
&& this.renderPromises.getSSRObservable(this.watchQueryOptions)
|
|
6304
6361
|
|| this.observable
|
|
6305
|
-
|| this.client.watchQuery(
|
|
6362
|
+
|| this.client.watchQuery(mergeOptions(this.queryHookOptions.defaultOptions, this.watchQueryOptions));
|
|
6306
6363
|
this.obsQueryFields = React.useMemo(function () { return ({
|
|
6307
6364
|
refetch: obsQuery.refetch.bind(obsQuery),
|
|
6308
6365
|
reobserve: obsQuery.reobserve.bind(obsQuery),
|
|
@@ -6312,11 +6369,11 @@ var InternalState = (function () {
|
|
|
6312
6369
|
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6313
6370
|
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6314
6371
|
}); }, [obsQuery]);
|
|
6315
|
-
|
|
6372
|
+
var ssrAllowed = !(this.queryHookOptions.ssr === false ||
|
|
6373
|
+
this.queryHookOptions.skip);
|
|
6374
|
+
if (this.renderPromises && ssrAllowed) {
|
|
6316
6375
|
this.renderPromises.registerSSRObservable(obsQuery);
|
|
6317
|
-
|
|
6318
|
-
this.queryHookOptions.skip);
|
|
6319
|
-
if (ssrAllowed && obsQuery.getCurrentResult().loading) {
|
|
6376
|
+
if (obsQuery.getCurrentResult().loading) {
|
|
6320
6377
|
this.renderPromises.addObservableQueryPromise(obsQuery);
|
|
6321
6378
|
}
|
|
6322
6379
|
}
|
|
@@ -6385,12 +6442,9 @@ var EAGER_METHODS = [
|
|
|
6385
6442
|
function useLazyQuery(query, options) {
|
|
6386
6443
|
var internalState = useInternalState(useApolloClient(options && options.client), query);
|
|
6387
6444
|
var execOptionsRef = React.useRef();
|
|
6388
|
-
var defaultOptions = internalState.client.defaultOptions.watchQuery;
|
|
6389
|
-
var initialFetchPolicy = (options && options.fetchPolicy) ||
|
|
6390
|
-
(execOptionsRef.current && execOptionsRef.current.fetchPolicy) ||
|
|
6391
|
-
(defaultOptions && defaultOptions.fetchPolicy) ||
|
|
6392
|
-
"cache-first";
|
|
6393
6445
|
var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign(tslib.__assign({}, options), execOptionsRef.current), { skip: !execOptionsRef.current }));
|
|
6446
|
+
var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
|
|
6447
|
+
internalState.getDefaultFetchPolicy();
|
|
6394
6448
|
var result = Object.assign(useQueryResult, {
|
|
6395
6449
|
called: !!execOptionsRef.current,
|
|
6396
6450
|
});
|
|
@@ -6414,22 +6468,12 @@ function useLazyQuery(query, options) {
|
|
|
6414
6468
|
}, []);
|
|
6415
6469
|
Object.assign(result, eagerMethods);
|
|
6416
6470
|
var execute = React.useCallback(function (executeOptions) {
|
|
6417
|
-
|
|
6471
|
+
execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
6418
6472
|
fetchPolicy: initialFetchPolicy,
|
|
6419
|
-
}
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
|
|
6424
|
-
if (errorPolicy === "none") {
|
|
6425
|
-
throw apolloQueryResult.error || new ApolloError({
|
|
6426
|
-
graphQLErrors: apolloQueryResult.errors,
|
|
6427
|
-
});
|
|
6428
|
-
}
|
|
6429
|
-
}
|
|
6430
|
-
return internalState.toQueryResult(apolloQueryResult);
|
|
6431
|
-
}).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
6432
|
-
internalState.forceUpdate();
|
|
6473
|
+
};
|
|
6474
|
+
var promise = internalState
|
|
6475
|
+
.asyncUpdate()
|
|
6476
|
+
.then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
6433
6477
|
promise.catch(function () { });
|
|
6434
6478
|
return promise;
|
|
6435
6479
|
}, []);
|