@apollo/client 3.8.0-alpha.11 → 3.8.0-alpha.12
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 +452 -281
- 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/ObservableQuery.d.ts +2 -1
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +30 -19
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +2 -0
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +60 -48
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +175 -82
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +175 -82
- package/core/equalByQuery.d.ts +4 -0
- package/core/equalByQuery.d.ts.map +1 -0
- package/{react/hooks/compareResults.js → core/equalByQuery.js} +14 -10
- package/core/equalByQuery.js.map +1 -0
- 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/errors/errors.cjs +17 -17
- package/errors/errors.cjs.map +1 -1
- package/errors/errors.cjs.native.js +17 -17
- package/errors/index.d.ts +24 -8
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +17 -19
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/link/batch-http/batch-http.cjs +23 -2
- package/link/batch-http/batch-http.cjs.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +23 -2
- package/link/batch-http/batchHttpLink.d.ts.map +1 -1
- package/link/batch-http/batchHttpLink.js +7 -2
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/core/types.d.ts +4 -0
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +21 -20
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs +59 -30
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +59 -30
- package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +34 -14
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +2 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/subscriptions/index.d.ts.map +1 -1
- package/link/subscriptions/index.js +10 -5
- package/link/subscriptions/index.js.map +1 -1
- package/link/subscriptions/subscriptions.cjs +9 -4
- package/link/subscriptions/subscriptions.cjs.map +1 -1
- package/link/subscriptions/subscriptions.cjs.native.js +9 -4
- package/link/utils/filterOperationVariables.d.ts +5 -0
- package/link/utils/filterOperationVariables.d.ts.map +1 -0
- package/link/utils/filterOperationVariables.js +18 -0
- package/link/utils/filterOperationVariables.js.map +1 -0
- package/link/utils/index.d.ts +1 -0
- package/link/utils/index.d.ts.map +1 -1
- package/link/utils/index.js +1 -0
- package/link/utils/index.js.map +1 -1
- package/link/utils/utils.cjs +18 -0
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +18 -0
- package/package.json +17 -17
- package/react/cache/QuerySubscription.js +1 -1
- package/react/cache/QuerySubscription.js.map +1 -1
- package/react/cache/SuspenseCache.d.ts +3 -2
- package/react/cache/SuspenseCache.d.ts.map +1 -1
- package/react/cache/SuspenseCache.js +6 -7
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/hooks/hooks.cjs +61 -84
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +61 -84
- package/react/hooks/internal/__use.d.ts +3 -1
- package/react/hooks/internal/__use.d.ts.map +1 -1
- package/react/hooks/internal/__use.js +16 -12
- package/react/hooks/internal/__use.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +13 -22
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +3 -3
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +26 -25
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
- package/react/hooks/useSuspenseQuery.js +6 -2
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.d.ts.map +1 -1
- package/react/index.js +1 -1
- package/react/index.js.map +1 -1
- package/react/react.cjs +7 -22
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +7 -22
- package/react/types/types.d.ts +1 -0
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
- package/testing/react/MockedProvider.d.ts +1 -1
- package/testing/react/MockedProvider.d.ts.map +1 -1
- package/testing/react/MockedProvider.js +7 -6
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +8 -124
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +8 -124
- package/utilities/common/incrementalResult.d.ts +2 -1
- package/utilities/common/incrementalResult.d.ts.map +1 -1
- package/utilities/common/incrementalResult.js +4 -0
- package/utilities/common/incrementalResult.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.map +1 -1
- package/utilities/common/objects.d.ts +1 -0
- package/utilities/common/objects.d.ts.map +1 -1
- package/utilities/common/objects.js +6 -0
- package/utilities/common/objects.js.map +1 -1
- package/utilities/common/omitDeep.d.ts +3 -0
- package/utilities/common/omitDeep.d.ts.map +1 -0
- package/utilities/common/omitDeep.js +42 -0
- package/utilities/common/omitDeep.js.map +1 -0
- package/utilities/common/stripTypename.d.ts +2 -0
- package/utilities/common/stripTypename.d.ts.map +1 -0
- package/utilities/common/stripTypename.js +5 -0
- package/utilities/common/stripTypename.js.map +1 -0
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +1 -0
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +26 -16
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +4 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +3 -0
- package/utilities/index.js.map +1 -1
- package/utilities/types/DeepOmit.d.ts +9 -0
- package/utilities/types/DeepOmit.d.ts.map +1 -0
- package/utilities/types/DeepOmit.js +2 -0
- package/utilities/types/DeepOmit.js.map +1 -0
- package/utilities/utilities.cjs +111 -15
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +111 -15
- package/version.js +1 -1
- package/react/hooks/compareResults.d.ts +0 -3
- package/react/hooks/compareResults.d.ts.map +0 -1
- package/react/hooks/compareResults.js.map +0 -1
|
@@ -11,6 +11,9 @@ var equality = require('@wry/equality');
|
|
|
11
11
|
var core = require('../../core');
|
|
12
12
|
var errors = require('../../errors');
|
|
13
13
|
var parser = require('../parser');
|
|
14
|
+
var cache = require('../../cache');
|
|
15
|
+
|
|
16
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
14
17
|
|
|
15
18
|
function _interopNamespace(e) {
|
|
16
19
|
if (e && e.__esModule) return e;
|
|
@@ -25,6 +28,7 @@ function _interopNamespace(e) {
|
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
31
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
28
32
|
|
|
29
33
|
function useApolloClient(override) {
|
|
30
34
|
var context$1 = React.useContext(context.getApolloContext());
|
|
@@ -37,8 +41,8 @@ function useApolloClient(override) {
|
|
|
37
41
|
|
|
38
42
|
var didWarnUncachedGetSnapshot = false;
|
|
39
43
|
var uSESKey = "useSyncExternalStore";
|
|
40
|
-
var realHook = React__namespace[uSESKey];
|
|
41
|
-
var useSyncExternalStore = realHook || (function (subscribe, getSnapshot, getServerSnapshot) {
|
|
44
|
+
var realHook$1 = React__namespace[uSESKey];
|
|
45
|
+
var useSyncExternalStore = realHook$1 || (function (subscribe, getSnapshot, getServerSnapshot) {
|
|
42
46
|
var value = getSnapshot();
|
|
43
47
|
if (globals.__DEV__ &&
|
|
44
48
|
!didWarnUncachedGetSnapshot &&
|
|
@@ -103,8 +107,6 @@ var InternalState = (function () {
|
|
|
103
107
|
function InternalState(client, query, previous) {
|
|
104
108
|
this.client = client;
|
|
105
109
|
this.query = query;
|
|
106
|
-
this.asyncResolveFns = new Set();
|
|
107
|
-
this.optionsToIgnoreOnce = new (utilities.canUseWeakSet ? WeakSet : Set)();
|
|
108
110
|
this.ssrDisabledResult = utilities.maybeDeepFreeze({
|
|
109
111
|
loading: true,
|
|
110
112
|
data: void 0,
|
|
@@ -128,20 +130,30 @@ var InternalState = (function () {
|
|
|
128
130
|
InternalState.prototype.forceUpdate = function () {
|
|
129
131
|
globals.__DEV__ && globals.invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
|
|
130
132
|
};
|
|
131
|
-
InternalState.prototype.
|
|
133
|
+
InternalState.prototype.executeQuery = function (options) {
|
|
132
134
|
var _this = this;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
var _a;
|
|
136
|
+
if (options.query) {
|
|
137
|
+
Object.assign(this, { query: options.query });
|
|
138
|
+
}
|
|
139
|
+
this.watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
140
|
+
var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
|
|
141
|
+
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
142
|
+
this.result = void 0;
|
|
143
|
+
this.forceUpdate();
|
|
144
|
+
return new Promise(function (resolve) {
|
|
145
|
+
var result;
|
|
146
|
+
concast.subscribe({
|
|
147
|
+
next: function (value) {
|
|
148
|
+
result = value;
|
|
149
|
+
},
|
|
150
|
+
error: function () {
|
|
151
|
+
resolve(_this.toQueryResult(_this.observable.getCurrentResult()));
|
|
152
|
+
},
|
|
153
|
+
complete: function () {
|
|
154
|
+
resolve(_this.toQueryResult(result));
|
|
155
|
+
}
|
|
156
|
+
});
|
|
145
157
|
});
|
|
146
158
|
};
|
|
147
159
|
InternalState.prototype.useQuery = function (options) {
|
|
@@ -197,22 +209,15 @@ var InternalState = (function () {
|
|
|
197
209
|
this.client.disableNetworkFetches,
|
|
198
210
|
]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
|
|
199
211
|
this.unsafeHandlePartialRefetch(result);
|
|
200
|
-
|
|
201
|
-
if (!queryResult.loading && this.asyncResolveFns.size) {
|
|
202
|
-
this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
|
|
203
|
-
this.asyncResolveFns.clear();
|
|
204
|
-
}
|
|
205
|
-
return queryResult;
|
|
212
|
+
return this.toQueryResult(result);
|
|
206
213
|
};
|
|
207
214
|
InternalState.prototype.useOptions = function (options) {
|
|
208
215
|
var _a;
|
|
209
216
|
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
210
217
|
var currentWatchQueryOptions = this.watchQueryOptions;
|
|
211
|
-
if (
|
|
212
|
-
!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
218
|
+
if (!equality.equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
213
219
|
this.watchQueryOptions = watchQueryOptions;
|
|
214
220
|
if (currentWatchQueryOptions && this.observable) {
|
|
215
|
-
this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
|
|
216
221
|
this.observable.reobserve(this.getObsQueryOptions());
|
|
217
222
|
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
218
223
|
this.result = void 0;
|
|
@@ -379,11 +384,15 @@ var EAGER_METHODS = [
|
|
|
379
384
|
'subscribeToMore',
|
|
380
385
|
];
|
|
381
386
|
function useLazyQuery(query, options) {
|
|
382
|
-
var _a
|
|
383
|
-
var abortControllersRef = React.useRef(new Set());
|
|
387
|
+
var _a;
|
|
384
388
|
var execOptionsRef = React.useRef();
|
|
385
|
-
var
|
|
386
|
-
var
|
|
389
|
+
var optionsRef = React.useRef();
|
|
390
|
+
var queryRef = React.useRef();
|
|
391
|
+
var merged = utilities.mergeOptions(options, execOptionsRef.current || {});
|
|
392
|
+
var document = (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query;
|
|
393
|
+
optionsRef.current = merged;
|
|
394
|
+
queryRef.current = document;
|
|
395
|
+
var internalState = useInternalState(useApolloClient(options && options.client), document);
|
|
387
396
|
var useQueryResult = internalState.useQuery(tslib.__assign(tslib.__assign({}, merged), { skip: !execOptionsRef.current }));
|
|
388
397
|
var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
|
|
389
398
|
internalState.getDefaultFetchPolicy();
|
|
@@ -409,28 +418,15 @@ function useLazyQuery(query, options) {
|
|
|
409
418
|
return eagerMethods;
|
|
410
419
|
}, []);
|
|
411
420
|
Object.assign(result, eagerMethods);
|
|
412
|
-
React.useEffect(function () {
|
|
413
|
-
return function () {
|
|
414
|
-
abortControllersRef.current.forEach(function (controller) {
|
|
415
|
-
controller.abort();
|
|
416
|
-
});
|
|
417
|
-
};
|
|
418
|
-
}, []);
|
|
419
421
|
var execute = React.useCallback(function (executeOptions) {
|
|
420
|
-
var controller = new AbortController();
|
|
421
|
-
abortControllersRef.current.add(controller);
|
|
422
422
|
execOptionsRef.current = executeOptions ? tslib.__assign(tslib.__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
423
423
|
fetchPolicy: initialFetchPolicy,
|
|
424
424
|
};
|
|
425
|
+
var options = utilities.mergeOptions(optionsRef.current, tslib.__assign({ query: queryRef.current }, execOptionsRef.current));
|
|
425
426
|
var promise = internalState
|
|
426
|
-
.
|
|
427
|
-
.then(function (queryResult) {
|
|
428
|
-
|
|
429
|
-
return Object.assign(queryResult, eagerMethods);
|
|
430
|
-
});
|
|
431
|
-
promise.catch(function () {
|
|
432
|
-
abortControllersRef.current.delete(controller);
|
|
433
|
-
});
|
|
427
|
+
.executeQuery(tslib.__assign(tslib.__assign({}, options), { skip: false }))
|
|
428
|
+
.then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
429
|
+
promise.catch(function () { });
|
|
434
430
|
return promise;
|
|
435
431
|
}, []);
|
|
436
432
|
return [execute, result];
|
|
@@ -732,42 +728,20 @@ function useStrictModeSafeCleanupEffect(cleanup) {
|
|
|
732
728
|
}, []);
|
|
733
729
|
}
|
|
734
730
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
function
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
fulfilledPromise.status = 'fulfilled';
|
|
748
|
-
fulfilledPromise.value = value;
|
|
749
|
-
}
|
|
750
|
-
}, function (reason) {
|
|
751
|
-
if (pendingPromise.status === 'pending') {
|
|
752
|
-
var rejectedPromise = pendingPromise;
|
|
753
|
-
rejectedPromise.status = 'rejected';
|
|
754
|
-
rejectedPromise.reason = reason;
|
|
731
|
+
var useKey = 'use';
|
|
732
|
+
var realHook = React__default[useKey];
|
|
733
|
+
var __use = realHook ||
|
|
734
|
+
function __use(promise) {
|
|
735
|
+
var statefulPromise = utilities.wrapPromiseWithState(promise);
|
|
736
|
+
switch (statefulPromise.status) {
|
|
737
|
+
case 'pending':
|
|
738
|
+
throw statefulPromise;
|
|
739
|
+
case 'rejected':
|
|
740
|
+
throw statefulPromise.reason;
|
|
741
|
+
case 'fulfilled':
|
|
742
|
+
return statefulPromise.value;
|
|
755
743
|
}
|
|
756
|
-
}
|
|
757
|
-
return promise;
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
function __use(promise) {
|
|
761
|
-
var statefulPromise = wrapPromiseWithState(promise);
|
|
762
|
-
switch (statefulPromise.status) {
|
|
763
|
-
case 'pending':
|
|
764
|
-
throw statefulPromise;
|
|
765
|
-
case 'rejected':
|
|
766
|
-
throw statefulPromise.reason;
|
|
767
|
-
case 'fulfilled':
|
|
768
|
-
return statefulPromise.value;
|
|
769
|
-
}
|
|
770
|
-
}
|
|
744
|
+
};
|
|
771
745
|
|
|
772
746
|
function useSuspenseCache(override) {
|
|
773
747
|
var context$1 = React.useContext(context.getApolloContext());
|
|
@@ -785,9 +759,12 @@ function useSuspenseQuery_experimental(query, options) {
|
|
|
785
759
|
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
786
760
|
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
|
|
787
761
|
var _a = watchQueryOptions.returnPartialData, returnPartialData = _a === void 0 ? false : _a, variables = watchQueryOptions.variables;
|
|
788
|
-
var _b = options.suspensePolicy, suspensePolicy = _b === void 0 ? 'always' : _b;
|
|
762
|
+
var _b = options.suspensePolicy, suspensePolicy = _b === void 0 ? 'always' : _b, _c = options.queryKey, queryKey = _c === void 0 ? [] : _c;
|
|
789
763
|
var shouldSuspend = suspensePolicy === 'always' || !didPreviouslySuspend.current;
|
|
790
|
-
var
|
|
764
|
+
var cacheKey = [client, query, cache.canonicalStringify(variables)].concat(queryKey);
|
|
765
|
+
var subscription = suspenseCache.getSubscription(cacheKey, function () {
|
|
766
|
+
return client.watchQuery(watchQueryOptions);
|
|
767
|
+
});
|
|
791
768
|
var dispose = useTrackedSubscriptions(subscription);
|
|
792
769
|
useStrictModeSafeCleanupEffect(dispose);
|
|
793
770
|
var result = useSyncExternalStore(subscription.listen, function () { return subscription.result; }, function () { return subscription.result; });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__use.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"__use.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"AAGA,KAAK,GAAG,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AASzC,eAAO,MAAM,KAAK,KAaf,CAAC"}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { wrapPromiseWithState } from "../../../utilities/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { wrapPromiseWithState } from "../../../utilities/index.js";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
var useKey = 'use';
|
|
4
|
+
var realHook = React[useKey];
|
|
5
|
+
export var __use = realHook ||
|
|
6
|
+
function __use(promise) {
|
|
7
|
+
var statefulPromise = wrapPromiseWithState(promise);
|
|
8
|
+
switch (statefulPromise.status) {
|
|
9
|
+
case 'pending':
|
|
10
|
+
throw statefulPromise;
|
|
11
|
+
case 'rejected':
|
|
12
|
+
throw statefulPromise.reason;
|
|
13
|
+
case 'fulfilled':
|
|
14
|
+
return statefulPromise.value;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
13
17
|
//# sourceMappingURL=__use.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__use.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"__use.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/__use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,IAAM,MAAM,GAAG,KAA2B,CAAC;AAC3C,IAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAoB,CAAC;AAIlD,MAAM,CAAC,IAAM,KAAK,GAChB,QAAQ;IACR,SAAS,KAAK,CAAS,OAAwB;QAC7C,IAAM,eAAe,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEtD,QAAQ,eAAe,CAAC,MAAM,EAAE;YAC9B,KAAK,SAAS;gBACZ,MAAM,eAAe,CAAC;YACxB,KAAK,UAAU;gBACb,MAAM,eAAe,CAAC,MAAM,CAAC;YAC/B,KAAK,WAAW;gBACd,OAAO,eAAe,CAAC,KAAK,CAAC;SAChC;IACH,CAAC,CAAC","sourcesContent":["import { wrapPromiseWithState } from '../../../utilities';\nimport React from 'react';\n\ntype Use = <T>(promise: Promise<T>) => T;\n// Prevent webpack from complaining about our feature detection of the\n// use property of the React namespace, which is expected not\n// to exist when using current stable versions, and that's fine.\nconst useKey = 'use' as keyof typeof React;\nconst realHook = React[useKey] as Use | undefined;\n\n// This is named with two underscores to allow this hook to evade typical rules of\n// hooks (i.e. it can be used conditionally)\nexport const __use =\n realHook ||\n function __use<TValue>(promise: Promise<TValue>) {\n const statefulPromise = wrapPromiseWithState(promise);\n\n switch (statefulPromise.status) {\n case 'pending':\n throw statefulPromise;\n case 'rejected':\n throw statefulPromise.reason;\n case 'fulfilled':\n return statefulPromise.value;\n }\n };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAEL,oBAAoB,EACpB,oBAAoB,EACpB,OAAO,EAER,MAAM,gBAAgB,CAAC;AAexB,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAClG,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,GAClE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"useLazyQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAEL,oBAAoB,EACpB,oBAAoB,EACpB,OAAO,EAER,MAAM,gBAAgB,CAAC;AAexB,wBAAgB,YAAY,CAAC,KAAK,GAAG,GAAG,EAAE,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAClG,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,GAClE,oBAAoB,CAAC,KAAK,EAAE,UAAU,CAAC,CA8EzC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
|
-
import { useCallback,
|
|
2
|
+
import { useCallback, useMemo, useRef } from 'react';
|
|
3
3
|
import { mergeOptions } from "../../utilities/index.js";
|
|
4
4
|
import { useInternalState } from "./useQuery.js";
|
|
5
5
|
import { useApolloClient } from "./useApolloClient.js";
|
|
@@ -12,11 +12,15 @@ var EAGER_METHODS = [
|
|
|
12
12
|
'subscribeToMore',
|
|
13
13
|
];
|
|
14
14
|
export function useLazyQuery(query, options) {
|
|
15
|
-
var _a
|
|
16
|
-
var abortControllersRef = useRef(new Set());
|
|
15
|
+
var _a;
|
|
17
16
|
var execOptionsRef = useRef();
|
|
18
|
-
var
|
|
19
|
-
var
|
|
17
|
+
var optionsRef = useRef();
|
|
18
|
+
var queryRef = useRef();
|
|
19
|
+
var merged = mergeOptions(options, execOptionsRef.current || {});
|
|
20
|
+
var document = (_a = merged === null || merged === void 0 ? void 0 : merged.query) !== null && _a !== void 0 ? _a : query;
|
|
21
|
+
optionsRef.current = merged;
|
|
22
|
+
queryRef.current = document;
|
|
23
|
+
var internalState = useInternalState(useApolloClient(options && options.client), document);
|
|
20
24
|
var useQueryResult = internalState.useQuery(__assign(__assign({}, merged), { skip: !execOptionsRef.current }));
|
|
21
25
|
var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
|
|
22
26
|
internalState.getDefaultFetchPolicy();
|
|
@@ -42,28 +46,15 @@ export function useLazyQuery(query, options) {
|
|
|
42
46
|
return eagerMethods;
|
|
43
47
|
}, []);
|
|
44
48
|
Object.assign(result, eagerMethods);
|
|
45
|
-
useEffect(function () {
|
|
46
|
-
return function () {
|
|
47
|
-
abortControllersRef.current.forEach(function (controller) {
|
|
48
|
-
controller.abort();
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
}, []);
|
|
52
49
|
var execute = useCallback(function (executeOptions) {
|
|
53
|
-
var controller = new AbortController();
|
|
54
|
-
abortControllersRef.current.add(controller);
|
|
55
50
|
execOptionsRef.current = executeOptions ? __assign(__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
|
|
56
51
|
fetchPolicy: initialFetchPolicy,
|
|
57
52
|
};
|
|
53
|
+
var options = mergeOptions(optionsRef.current, __assign({ query: queryRef.current }, execOptionsRef.current));
|
|
58
54
|
var promise = internalState
|
|
59
|
-
.
|
|
60
|
-
.then(function (queryResult) {
|
|
61
|
-
|
|
62
|
-
return Object.assign(queryResult, eagerMethods);
|
|
63
|
-
});
|
|
64
|
-
promise.catch(function () {
|
|
65
|
-
abortControllersRef.current.delete(controller);
|
|
66
|
-
});
|
|
55
|
+
.executeQuery(__assign(__assign({}, options), { skip: false }))
|
|
56
|
+
.then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
|
|
57
|
+
promise.catch(function () { });
|
|
67
58
|
return promise;
|
|
68
59
|
}, []);
|
|
69
60
|
return [execute, result];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAQ/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAC1B,KAA0D,EAC1D,OAAmE;;IAEnE,IAAM,cAAc,GAAG,MAAM,EAAwD,CAAC;IACtF,IAAM,UAAU,GAAG,MAAM,EAA2C,CAAC;IACrE,IAAM,QAAQ,GAAG,MAAM,EAAuD,CAAC;IAC/E,IAAM,MAAM,GAAG,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;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C;IAEP,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAEpC,IAAM,OAAO,GAAG,WAAW,CAEzB,UAAA,cAAc;QACd,cAAc,CAAC,OAAO,GAAG,cAAc,CAAC,CAAC,uBACpC,cAAc,KACjB,WAAW,EAAE,cAAc,CAAC,WAAW,IAAI,kBAAkB,IAC7D,CAAC,CAAC;YACF,WAAW,EAAE,kBAAkB;SAChC,CAAC;QAEF,IAAM,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,OAAO,aAC7C,KAAK,EAAE,QAAQ,CAAC,OAAO,IACpB,cAAc,CAAC,OAAO,EACzB,CAAA;QAEF,IAAM,OAAO,GAAG,aAAa;aAC1B,YAAY,uBAAM,OAAO,KAAE,IAAI,EAAE,KAAK,IAAG;aACzC,IAAI,CAAC,UAAC,WAAW,IAAK,OAAA,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,CAAC,EAAxC,CAAwC,CAAC,CAAC;QAInE,OAAO,CAAC,KAAK,CAAC,cAAO,CAAC,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useMemo, useRef } from 'react';\n\nimport { OperationVariables } from '../../core';\nimport { mergeOptions } from '../../utilities';\nimport {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryResult,\n} from '../types/types';\nimport { useInternalState } from './useQuery';\nimport { useApolloClient } from './useApolloClient';\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n 'refetch',\n 'reobserve',\n 'fetchMore',\n 'updateQuery',\n 'startPolling',\n 'subscribeToMore',\n] as const;\n\nexport function useLazyQuery<TData = any, TVariables extends OperationVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n const execOptionsRef = useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>();\n const optionsRef = useRef<LazyQueryHookOptions<TData, TVariables>>();\n const queryRef = useRef<DocumentNode | TypedDocumentNode<TData, TVariables>>();\n const merged = mergeOptions(options, execOptionsRef.current || {});\n const document = merged?.query ?? query;\n\n // Use refs to track options and the used query to ensure the `execute` \n // function remains referentially stable between renders.\n optionsRef.current = merged;\n queryRef.current = document;\n\n const internalState = useInternalState<TData, TVariables>(\n useApolloClient(options && options.client),\n document\n );\n\n const useQueryResult = internalState.useQuery({\n ...merged,\n skip: !execOptionsRef.current,\n });\n\n const initialFetchPolicy =\n useQueryResult.observable.options.initialFetchPolicy ||\n internalState.getDefaultFetchPolicy();\n\n const result: QueryResult<TData, TVariables> =\n Object.assign(useQueryResult, {\n called: !!execOptionsRef.current,\n });\n\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = result[key];\n eagerMethods[key] = function () {\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n internalState.forceUpdate();\n }\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods;\n }, []);\n\n Object.assign(result, eagerMethods);\n\n const execute = useCallback<\n LazyQueryResultTuple<TData, TVariables>[0]\n >(executeOptions => {\n execOptionsRef.current = executeOptions ? {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n } : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const options = mergeOptions(optionsRef.current, {\n query: queryRef.current,\n ...execOptionsRef.current,\n })\n\n const promise = internalState\n .executeQuery({ ...options, skip: false })\n .then((queryResult) => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n }, []);\n\n return [execute, result];\n}\n"]}
|
|
@@ -9,9 +9,9 @@ declare class InternalState<TData, TVariables extends OperationVariables> {
|
|
|
9
9
|
readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
|
10
10
|
constructor(client: ReturnType<typeof useApolloClient>, query: DocumentNode | TypedDocumentNode<TData, TVariables>, previous?: InternalState<TData, TVariables>);
|
|
11
11
|
forceUpdate(): void;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
executeQuery(options: QueryHookOptions<TData, TVariables> & {
|
|
13
|
+
query?: DocumentNode;
|
|
14
|
+
}): Promise<QueryResult<TData, TVariables>>;
|
|
15
15
|
useQuery(options: QueryHookOptions<TData, TVariables>): QueryResult<TData, TVariables>;
|
|
16
16
|
private renderPromises;
|
|
17
17
|
private queryHookOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGrF,OAAO,EACL,YAAY,EACZ,iBAAiB,EAGjB,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EAEX,OAAO,EACR,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AASpD,wBAAgB,QAAQ,CACtB,KAAK,GAAG,GAAG,EACX,UAAU,SAAS,kBAAkB,GAAG,kBAAkB,EAE1D,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,GAAE,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,O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AO;IAEf,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,cAAc,CAGpB;IAEF,OAAO,CAAC,kBAAkB;IAuC1B,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,YAAY,CAAoB;IAExC,OAAO,CAAC,SAAS;IAYjB,OAAO,CAAC,sBAAsB;IAwB9B,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,kBAAkB,CAGtB;IAEJ,aAAa,CACX,MAAM,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAC/B,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC;IA2BjC,OAAO,CAAC,0BAA0B;CAoBnC"}
|
package/react/hooks/useQuery.js
CHANGED
|
@@ -9,7 +9,7 @@ import { ApolloError } from "../../errors/index.js";
|
|
|
9
9
|
import { NetworkStatus, } from "../../core/index.js";
|
|
10
10
|
import { DocumentType, verifyDocumentType } from "../parser/index.js";
|
|
11
11
|
import { useApolloClient } from "./useApolloClient.js";
|
|
12
|
-
import { canUseWeakMap,
|
|
12
|
+
import { canUseWeakMap, compact, isNonEmptyArray, maybeDeepFreeze } from "../../utilities/index.js";
|
|
13
13
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
14
14
|
export function useQuery(query, options) {
|
|
15
15
|
if (options === void 0) { options = Object.create(null); }
|
|
@@ -33,8 +33,6 @@ var InternalState = (function () {
|
|
|
33
33
|
function InternalState(client, query, previous) {
|
|
34
34
|
this.client = client;
|
|
35
35
|
this.query = query;
|
|
36
|
-
this.asyncResolveFns = new Set();
|
|
37
|
-
this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
|
|
38
36
|
this.ssrDisabledResult = maybeDeepFreeze({
|
|
39
37
|
loading: true,
|
|
40
38
|
data: void 0,
|
|
@@ -58,20 +56,30 @@ var InternalState = (function () {
|
|
|
58
56
|
InternalState.prototype.forceUpdate = function () {
|
|
59
57
|
__DEV__ && invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
|
|
60
58
|
};
|
|
61
|
-
InternalState.prototype.
|
|
59
|
+
InternalState.prototype.executeQuery = function (options) {
|
|
62
60
|
var _this = this;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
61
|
+
var _a;
|
|
62
|
+
if (options.query) {
|
|
63
|
+
Object.assign(this, { query: options.query });
|
|
64
|
+
}
|
|
65
|
+
this.watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
66
|
+
var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
|
|
67
|
+
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
68
|
+
this.result = void 0;
|
|
69
|
+
this.forceUpdate();
|
|
70
|
+
return new Promise(function (resolve) {
|
|
71
|
+
var result;
|
|
72
|
+
concast.subscribe({
|
|
73
|
+
next: function (value) {
|
|
74
|
+
result = value;
|
|
75
|
+
},
|
|
76
|
+
error: function () {
|
|
77
|
+
resolve(_this.toQueryResult(_this.observable.getCurrentResult()));
|
|
78
|
+
},
|
|
79
|
+
complete: function () {
|
|
80
|
+
resolve(_this.toQueryResult(result));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
75
83
|
});
|
|
76
84
|
};
|
|
77
85
|
InternalState.prototype.useQuery = function (options) {
|
|
@@ -127,22 +135,15 @@ var InternalState = (function () {
|
|
|
127
135
|
this.client.disableNetworkFetches,
|
|
128
136
|
]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
|
|
129
137
|
this.unsafeHandlePartialRefetch(result);
|
|
130
|
-
|
|
131
|
-
if (!queryResult.loading && this.asyncResolveFns.size) {
|
|
132
|
-
this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
|
|
133
|
-
this.asyncResolveFns.clear();
|
|
134
|
-
}
|
|
135
|
-
return queryResult;
|
|
138
|
+
return this.toQueryResult(result);
|
|
136
139
|
};
|
|
137
140
|
InternalState.prototype.useOptions = function (options) {
|
|
138
141
|
var _a;
|
|
139
142
|
var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
|
|
140
143
|
var currentWatchQueryOptions = this.watchQueryOptions;
|
|
141
|
-
if (
|
|
142
|
-
!equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
144
|
+
if (!equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
143
145
|
this.watchQueryOptions = watchQueryOptions;
|
|
144
146
|
if (currentWatchQueryOptions && this.observable) {
|
|
145
|
-
this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
|
|
146
147
|
this.observable.reobserve(this.getObsQueryOptions());
|
|
147
148
|
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
148
149
|
this.result = void 0;
|