@apollo/client 3.7.0-alpha.2 → 3.7.0-alpha.3
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 +90 -29
- 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.map +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/package.json +6 -7
- package/react/hooks/hooks.cjs +116 -47
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +5 -17
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +3 -0
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +29 -9
- 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 +50 -0
- package/react/hooks/useSyncExternalStore.js.map +1 -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/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js +5 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/utilities.cjs +12 -4
- package/utilities/utilities.cjs.map +1 -1
- 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) {
|
|
@@ -951,9 +953,12 @@ var Concast = (function (_super) {
|
|
|
951
953
|
}
|
|
952
954
|
},
|
|
953
955
|
complete: function () {
|
|
954
|
-
|
|
956
|
+
var sub = _this.sub;
|
|
957
|
+
if (sub !== null) {
|
|
955
958
|
var value = _this.sources.shift();
|
|
956
959
|
if (!value) {
|
|
960
|
+
if (sub)
|
|
961
|
+
setTimeout(function () { return sub.unsubscribe(); });
|
|
957
962
|
_this.sub = null;
|
|
958
963
|
if (_this.latest &&
|
|
959
964
|
_this.latest[0] === "next") {
|
|
@@ -1021,7 +1026,7 @@ var Concast = (function (_super) {
|
|
|
1021
1026
|
if (this.observers.delete(observer) &&
|
|
1022
1027
|
--this.addCount < 1 &&
|
|
1023
1028
|
!quietly) {
|
|
1024
|
-
this.handlers.
|
|
1029
|
+
this.handlers.complete();
|
|
1025
1030
|
}
|
|
1026
1031
|
};
|
|
1027
1032
|
Concast.prototype.cleanup = function (callback) {
|
|
@@ -1298,7 +1303,7 @@ var concat = ApolloLink.concat;
|
|
|
1298
1303
|
|
|
1299
1304
|
var execute = ApolloLink.execute;
|
|
1300
1305
|
|
|
1301
|
-
var version = '3.7.0-alpha.
|
|
1306
|
+
var version = '3.7.0-alpha.3';
|
|
1302
1307
|
|
|
1303
1308
|
var hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
1304
1309
|
function parseAndCheckHttpResponse(operations) {
|
|
@@ -6036,6 +6041,53 @@ function useApolloClient(override) {
|
|
|
6036
6041
|
return client;
|
|
6037
6042
|
}
|
|
6038
6043
|
|
|
6044
|
+
var didWarnUncachedGetSnapshot = false;
|
|
6045
|
+
var useSyncExternalStore = function (subscribe, getSnapshot, getServerSnapshot) {
|
|
6046
|
+
var realHook = React__namespace.useSyncExternalStore;
|
|
6047
|
+
if (realHook) {
|
|
6048
|
+
return realHook(subscribe, getSnapshot, getServerSnapshot);
|
|
6049
|
+
}
|
|
6050
|
+
var value = getSnapshot();
|
|
6051
|
+
if (__DEV__ &&
|
|
6052
|
+
!didWarnUncachedGetSnapshot &&
|
|
6053
|
+
value !== getSnapshot()) {
|
|
6054
|
+
didWarnUncachedGetSnapshot = true;
|
|
6055
|
+
__DEV__ && tsInvariant.invariant.error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
6056
|
+
}
|
|
6057
|
+
var _a = React__namespace.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
|
|
6058
|
+
if (canUseLayoutEffect) {
|
|
6059
|
+
React__namespace.useLayoutEffect(function () {
|
|
6060
|
+
Object.assign(inst, { value: value, getSnapshot: getSnapshot });
|
|
6061
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
6062
|
+
forceUpdate({ inst: inst });
|
|
6063
|
+
}
|
|
6064
|
+
}, [subscribe, value, getSnapshot]);
|
|
6065
|
+
}
|
|
6066
|
+
else {
|
|
6067
|
+
Object.assign(inst, { value: value, getSnapshot: getSnapshot });
|
|
6068
|
+
}
|
|
6069
|
+
React__namespace.useEffect(function () {
|
|
6070
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
6071
|
+
forceUpdate({ inst: inst });
|
|
6072
|
+
}
|
|
6073
|
+
return subscribe(function handleStoreChange() {
|
|
6074
|
+
if (checkIfSnapshotChanged(inst)) {
|
|
6075
|
+
forceUpdate({ inst: inst });
|
|
6076
|
+
}
|
|
6077
|
+
});
|
|
6078
|
+
}, [subscribe]);
|
|
6079
|
+
return value;
|
|
6080
|
+
};
|
|
6081
|
+
function checkIfSnapshotChanged(_a) {
|
|
6082
|
+
var value = _a.value, getSnapshot = _a.getSnapshot;
|
|
6083
|
+
try {
|
|
6084
|
+
return value !== getSnapshot();
|
|
6085
|
+
}
|
|
6086
|
+
catch (_b) {
|
|
6087
|
+
return true;
|
|
6088
|
+
}
|
|
6089
|
+
}
|
|
6090
|
+
|
|
6039
6091
|
exports.DocumentType = void 0;
|
|
6040
6092
|
(function (DocumentType) {
|
|
6041
6093
|
DocumentType[DocumentType["Query"] = 0] = "Query";
|
|
@@ -6152,6 +6204,8 @@ var InternalState = (function () {
|
|
|
6152
6204
|
function InternalState(client, query) {
|
|
6153
6205
|
this.client = client;
|
|
6154
6206
|
this.query = query;
|
|
6207
|
+
this.asyncResolveFns = new Set();
|
|
6208
|
+
this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
|
|
6155
6209
|
this.ssrDisabledResult = maybeDeepFreeze({
|
|
6156
6210
|
loading: true,
|
|
6157
6211
|
data: void 0,
|
|
@@ -6168,13 +6222,22 @@ var InternalState = (function () {
|
|
|
6168
6222
|
verifyDocumentType(query, exports.DocumentType.Query);
|
|
6169
6223
|
}
|
|
6170
6224
|
InternalState.prototype.forceUpdate = function () {
|
|
6225
|
+
__DEV__ && tsInvariant.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
|
|
6226
|
+
};
|
|
6227
|
+
InternalState.prototype.asyncUpdate = function () {
|
|
6228
|
+
var _this = this;
|
|
6229
|
+
return new Promise(function (resolve) {
|
|
6230
|
+
_this.asyncResolveFns.add(resolve);
|
|
6231
|
+
_this.optionsToIgnoreOnce.add(_this.watchQueryOptions);
|
|
6232
|
+
_this.forceUpdate();
|
|
6233
|
+
});
|
|
6171
6234
|
};
|
|
6172
6235
|
InternalState.prototype.useQuery = function (options) {
|
|
6173
6236
|
var _this = this;
|
|
6174
6237
|
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
6175
6238
|
this.useOptions(options);
|
|
6176
6239
|
var obsQuery = this.useObservableQuery();
|
|
6177
|
-
var result =
|
|
6240
|
+
var result = useSyncExternalStore(React.useCallback(function () {
|
|
6178
6241
|
if (_this.renderPromises) {
|
|
6179
6242
|
return function () { };
|
|
6180
6243
|
}
|
|
@@ -6222,15 +6285,22 @@ var InternalState = (function () {
|
|
|
6222
6285
|
this.client.disableNetworkFetches,
|
|
6223
6286
|
]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
|
|
6224
6287
|
this.unsafeHandlePartialRefetch(result);
|
|
6225
|
-
|
|
6288
|
+
var queryResult = this.toQueryResult(result);
|
|
6289
|
+
if (!queryResult.loading && this.asyncResolveFns.size) {
|
|
6290
|
+
this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
|
|
6291
|
+
this.asyncResolveFns.clear();
|
|
6292
|
+
}
|
|
6293
|
+
return queryResult;
|
|
6226
6294
|
};
|
|
6227
6295
|
InternalState.prototype.useOptions = function (options) {
|
|
6228
6296
|
var _a;
|
|
6229
6297
|
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
6230
6298
|
var currentWatchQueryOptions = this.watchQueryOptions;
|
|
6231
|
-
if (
|
|
6299
|
+
if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
|
|
6300
|
+
!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
6232
6301
|
this.watchQueryOptions = watchQueryOptions;
|
|
6233
6302
|
if (currentWatchQueryOptions && this.observable) {
|
|
6303
|
+
this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
|
|
6234
6304
|
this.observable.reobserve(watchQueryOptions);
|
|
6235
6305
|
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
6236
6306
|
this.result = void 0;
|
|
@@ -6239,7 +6309,8 @@ var InternalState = (function () {
|
|
|
6239
6309
|
this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;
|
|
6240
6310
|
this.onError = options.onError || InternalState.prototype.onError;
|
|
6241
6311
|
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
6242
|
-
this.queryHookOptions.ssr === false
|
|
6312
|
+
this.queryHookOptions.ssr === false &&
|
|
6313
|
+
!this.queryHookOptions.skip) {
|
|
6243
6314
|
this.result = this.ssrDisabledResult;
|
|
6244
6315
|
}
|
|
6245
6316
|
else if (this.queryHookOptions.skip ||
|
|
@@ -6301,11 +6372,11 @@ var InternalState = (function () {
|
|
|
6301
6372
|
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
6302
6373
|
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
6303
6374
|
}); }, [obsQuery]);
|
|
6304
|
-
|
|
6375
|
+
var ssrAllowed = !(this.queryHookOptions.ssr === false ||
|
|
6376
|
+
this.queryHookOptions.skip);
|
|
6377
|
+
if (this.renderPromises && ssrAllowed) {
|
|
6305
6378
|
this.renderPromises.registerSSRObservable(obsQuery);
|
|
6306
|
-
|
|
6307
|
-
this.queryHookOptions.skip);
|
|
6308
|
-
if (ssrAllowed && obsQuery.getCurrentResult().loading) {
|
|
6379
|
+
if (obsQuery.getCurrentResult().loading) {
|
|
6309
6380
|
this.renderPromises.addObservableQueryPromise(obsQuery);
|
|
6310
6381
|
}
|
|
6311
6382
|
}
|
|
@@ -6400,22 +6471,12 @@ function useLazyQuery(query, options) {
|
|
|
6400
6471
|
}, []);
|
|
6401
6472
|
Object.assign(result, eagerMethods);
|
|
6402
6473
|
var execute = React.useCallback(function (executeOptions) {
|
|
6403
|
-
|
|
6474
|
+
execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
6404
6475
|
fetchPolicy: initialFetchPolicy,
|
|
6405
|
-
}
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
var _a = result.observable.options.errorPolicy, errorPolicy = _a === void 0 ? "none" : _a;
|
|
6410
|
-
if (errorPolicy === "none") {
|
|
6411
|
-
throw apolloQueryResult.error || new ApolloError({
|
|
6412
|
-
graphQLErrors: apolloQueryResult.errors,
|
|
6413
|
-
});
|
|
6414
|
-
}
|
|
6415
|
-
}
|
|
6416
|
-
return internalState.toQueryResult(apolloQueryResult);
|
|
6417
|
-
}).then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
6418
|
-
internalState.forceUpdate();
|
|
6476
|
+
};
|
|
6477
|
+
var promise = internalState
|
|
6478
|
+
.asyncUpdate()
|
|
6479
|
+
.then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
6419
6480
|
promise.catch(function () { });
|
|
6420
6481
|
return promise;
|
|
6421
6482
|
}, []);
|