@apollo/client 3.14.0-rc.0 → 3.14.1
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/CHANGELOG.md +44 -0
- package/apollo-client.cjs +85 -77
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +14 -41
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +14 -41
- package/cache/core/cache.js +1 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/inmemory/inMemoryCache.js +1 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/core/ApolloClient.js +1 -1
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +1 -0
- package/core/ObservableQuery.js +10 -6
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js +1 -1
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.js +1 -1
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +38 -61
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +38 -61
- package/dev/dev.cjs +49 -53
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +49 -53
- package/invariantErrorCodes.js +48 -53
- package/link/core/ApolloLink.js +1 -1
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +1 -15
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +1 -15
- package/package.json +1 -1
- package/react/components/components.cjs +2 -14
- package/react/components/components.cjs.map +1 -1
- package/react/components/components.cjs.native.js +2 -14
- package/react/hoc/graphql.js +1 -1
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc.cjs +12 -31
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +12 -31
- package/react/hoc/mutation-hoc.js +1 -1
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.js +1 -1
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.js +1 -1
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hooks/hooks.cjs +26 -52
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +26 -52
- package/react/hooks/internal/useWarnRemoved.d.ts +1 -1
- package/react/hooks/internal/useWarnRemoved.js +1 -1
- package/react/hooks/internal/useWarnRemoved.js.map +1 -1
- package/react/hooks/internal/useWarnRemovedOption.d.ts +2 -1
- package/react/hooks/internal/useWarnRemovedOption.js +7 -5
- package/react/hooks/internal/useWarnRemovedOption.js.map +1 -1
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useBackgroundQuery.js +1 -1
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +1 -1
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +3 -3
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.js +3 -3
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useQuery.js +3 -3
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +3 -3
- package/react/hooks/useSuspenseQuery.js +3 -3
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.js +2 -2
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/internal.cjs +3 -14
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +3 -14
- package/react/parser/index.js +7 -7
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +9 -29
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +9 -29
- package/react/query-preloader/createQueryPreloader.js +1 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/react.cjs +4 -31
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +4 -31
- package/testing/core/core.cjs +4 -4
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +4 -4
- package/testing/core/mocking/mockLink.d.ts +13 -0
- package/testing/core/mocking/mockLink.js +4 -4
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/internal/disposables/index.d.ts +1 -0
- package/testing/internal/disposables/index.js +1 -0
- package/testing/internal/disposables/index.js.map +1 -1
- package/testing/internal/disposables/withMutedDeprecations.d.ts +4 -0
- package/testing/internal/disposables/withMutedDeprecations.js +13 -0
- package/testing/internal/disposables/withMutedDeprecations.js.map +1 -0
- package/testing/react/MockedProvider.js +1 -1
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +5 -32
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +5 -32
- package/utilities/deprecation/index.d.ts +0 -3
- package/utilities/deprecation/index.js +4 -12
- package/utilities/deprecation/index.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/directives.js +7 -7
- package/utilities/graphql/fragments.js +3 -3
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/storeUtils.js +1 -1
- package/utilities/graphql/transform.js +2 -2
- package/utilities/index.d.ts +2 -0
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/utilities.cjs +54 -22
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +54 -22
- package/version.js +1 -1
- package/.changeset/breezy-lions-rule.md +0 -5
- package/.changeset/chilled-cameras-scream.md +0 -5
- package/.changeset/great-jobs-fetch.md +0 -5
- package/.changeset/great-suns-cover.md +0 -5
- package/.changeset/perfect-donuts-roll.md +0 -5
- package/.changeset/popular-waves-drop.md +0 -5
- package/.changeset/pre.json +0 -20
- package/.changeset/shy-boxes-exercise.md +0 -5
- package/.changeset/shy-dragons-tease.md +0 -5
- package/.changeset/smooth-countries-cough.md +0 -5
- package/.changeset/spotty-walls-repair.md +0 -5
- package/.changeset/tidy-bulldogs-exercise.md +0 -5
|
@@ -11,7 +11,6 @@ var equal = require('@wry/equality');
|
|
|
11
11
|
var errors = require('../../errors');
|
|
12
12
|
var core = require('../../core');
|
|
13
13
|
var parser = require('../parser');
|
|
14
|
-
var optimism = require('optimism');
|
|
15
14
|
var tsInvariant = require('ts-invariant');
|
|
16
15
|
var internal = require('../internal');
|
|
17
16
|
var cache = require('../../cache');
|
|
@@ -36,7 +35,7 @@ var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
|
36
35
|
function useApolloClient(override) {
|
|
37
36
|
var context$1 = React__namespace.useContext(context.getApolloContext());
|
|
38
37
|
var client = override || context$1.client;
|
|
39
|
-
globals.invariant(!!client,
|
|
38
|
+
globals.invariant(!!client, 78);
|
|
40
39
|
return client;
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -51,7 +50,7 @@ var useSyncExternalStore = realHook$1 ||
|
|
|
51
50
|
!didWarnUncachedGetSnapshot &&
|
|
52
51
|
value !== getSnapshot()) {
|
|
53
52
|
didWarnUncachedGetSnapshot = true;
|
|
54
|
-
globalThis.__DEV__ !== false && globals.invariant.error(
|
|
53
|
+
globalThis.__DEV__ !== false && globals.invariant.error(91);
|
|
55
54
|
}
|
|
56
55
|
var _a = React__namespace.useState({
|
|
57
56
|
inst: { value: value, getSnapshot: getSnapshot },
|
|
@@ -122,40 +121,15 @@ function useRenderGuard() {
|
|
|
122
121
|
}, []);
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
var muteAllDeprecations = Symbol.for("apollo.deprecations");
|
|
126
|
-
var global$2 = globals.global;
|
|
127
|
-
var slot = new optimism.Slot();
|
|
128
|
-
function isMuted(name) {
|
|
129
|
-
return global$2[muteAllDeprecations] || (slot.getValue() || []).includes(name);
|
|
130
|
-
}
|
|
131
|
-
function muteDeprecations(name) {
|
|
132
|
-
var args = [];
|
|
133
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
134
|
-
args[_i - 1] = arguments[_i];
|
|
135
|
-
}
|
|
136
|
-
return slot.withValue.apply(slot, tslib.__spreadArray([Array.isArray(name) ? name : [name]], args, false));
|
|
137
|
-
}
|
|
138
|
-
function warnRemovedOption(options, name, callSite, recommendation) {
|
|
139
|
-
if (recommendation === void 0) { recommendation = "Please remove this option."; }
|
|
140
|
-
warnDeprecated(name, function () {
|
|
141
|
-
if (name in options) {
|
|
142
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(104, callSite, name, recommendation);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
function warnDeprecated(name, cb) {
|
|
147
|
-
if (!isMuted(name)) {
|
|
148
|
-
cb();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
124
|
function useWarnRemovedOption(options, name, callSite, recommendation) {
|
|
153
125
|
"use no memo";
|
|
154
126
|
if (recommendation === void 0) { recommendation = "Please remove this option."; }
|
|
155
127
|
var didWarn = React__namespace.useRef(false);
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
128
|
+
if (globalThis.__DEV__ !== false) {
|
|
129
|
+
if (name in options && !didWarn.current) {
|
|
130
|
+
utilities.warnRemovedOption(options, name, callSite, recommendation);
|
|
131
|
+
didWarn.current = true;
|
|
132
|
+
}
|
|
159
133
|
}
|
|
160
134
|
}
|
|
161
135
|
|
|
@@ -211,7 +185,7 @@ function useInternalState(client, query, options, renderPromises, makeWatchQuery
|
|
|
211
185
|
(renderPromises &&
|
|
212
186
|
renderPromises.getSSRObservable(makeWatchQueryOptions())) ||
|
|
213
187
|
core.ObservableQuery["inactiveOnCreation"].withValue(!renderPromises, function () {
|
|
214
|
-
return muteDeprecations("canonizeResults", function () {
|
|
188
|
+
return utilities.muteDeprecations(["canonizeResults", "partialRefetch"], function () {
|
|
215
189
|
return client.watchQuery(getObsQueryOptions(void 0, client, options, makeWatchQueryOptions()));
|
|
216
190
|
});
|
|
217
191
|
}),
|
|
@@ -486,7 +460,7 @@ function bindObservableMethods(observable) {
|
|
|
486
460
|
args[_i] = arguments[_i];
|
|
487
461
|
}
|
|
488
462
|
if (globalThis.__DEV__ !== false) {
|
|
489
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
463
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(83);
|
|
490
464
|
}
|
|
491
465
|
return observable.reobserve.apply(observable, args);
|
|
492
466
|
},
|
|
@@ -498,7 +472,7 @@ function bindObservableMethods(observable) {
|
|
|
498
472
|
};
|
|
499
473
|
}
|
|
500
474
|
|
|
501
|
-
var version = "3.14.
|
|
475
|
+
var version = "3.14.1";
|
|
502
476
|
|
|
503
477
|
function maybe(thunk) {
|
|
504
478
|
try {
|
|
@@ -655,7 +629,7 @@ function useLazyQuery(query, options) {
|
|
|
655
629
|
eagerMethods[key] = function () {
|
|
656
630
|
if (globalThis.__DEV__ !== false) {
|
|
657
631
|
if (key === "reobserve") {
|
|
658
|
-
globalThis.__DEV__ !== false && invariant.warn(
|
|
632
|
+
globalThis.__DEV__ !== false && invariant.warn(79);
|
|
659
633
|
}
|
|
660
634
|
}
|
|
661
635
|
if (!execOptionsRef.current) {
|
|
@@ -678,19 +652,19 @@ function useLazyQuery(query, options) {
|
|
|
678
652
|
var execute = React__namespace.useCallback(function (executeOptions) {
|
|
679
653
|
if (globalThis.__DEV__ !== false) {
|
|
680
654
|
if (calledDuringRender()) {
|
|
681
|
-
globalThis.__DEV__ !== false && invariant.warn(
|
|
655
|
+
globalThis.__DEV__ !== false && invariant.warn(80);
|
|
682
656
|
}
|
|
683
657
|
for (var _i = 0, REMOVED_EXECUTE_OPTIONS_1 = REMOVED_EXECUTE_OPTIONS; _i < REMOVED_EXECUTE_OPTIONS_1.length; _i++) {
|
|
684
658
|
var name_1 = REMOVED_EXECUTE_OPTIONS_1[_i];
|
|
685
659
|
if (!warnRef.current.has(name_1)) {
|
|
686
|
-
warnRemovedOption(executeOptions || {}, name_1, "useLazyQuery.execute");
|
|
660
|
+
utilities.warnRemovedOption(executeOptions || {}, name_1, "useLazyQuery.execute");
|
|
687
661
|
warnRef.current.add(name_1);
|
|
688
662
|
}
|
|
689
663
|
}
|
|
690
664
|
for (var _a = 0, DEPRECATED_EXECUTE_OPTIONS_1 = DEPRECATED_EXECUTE_OPTIONS; _a < DEPRECATED_EXECUTE_OPTIONS_1.length; _a++) {
|
|
691
665
|
var name_2 = DEPRECATED_EXECUTE_OPTIONS_1[_a];
|
|
692
666
|
if (!warnRef.current.has(name_2)) {
|
|
693
|
-
warnRemovedOption(executeOptions || {}, name_2, "useLazyQuery.execute", "Please pass the option to the `useLazyQuery` hook instead.");
|
|
667
|
+
utilities.warnRemovedOption(executeOptions || {}, name_2, "useLazyQuery.execute", "Please pass the option to the `useLazyQuery` hook instead.");
|
|
694
668
|
warnRef.current.add(name_2);
|
|
695
669
|
}
|
|
696
670
|
}
|
|
@@ -869,10 +843,10 @@ function useSubscription(subscription, options) {
|
|
|
869
843
|
if (!hasIssuedDeprecationWarningRef.current) {
|
|
870
844
|
hasIssuedDeprecationWarningRef.current = true;
|
|
871
845
|
if (options.onSubscriptionData) {
|
|
872
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(options.onData ?
|
|
846
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(options.onData ? 84 : 85);
|
|
873
847
|
}
|
|
874
848
|
if (options.onSubscriptionComplete) {
|
|
875
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(options.onComplete ?
|
|
849
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(options.onComplete ? 86 : 87);
|
|
876
850
|
}
|
|
877
851
|
}
|
|
878
852
|
var skip = options.skip, fetchPolicy = options.fetchPolicy, errorPolicy = options.errorPolicy, shouldResubscribe = options.shouldResubscribe, context = options.context, extensions = options.extensions, ignoreResults = options.ignoreResults;
|
|
@@ -993,7 +967,7 @@ function useSubscription(subscription, options) {
|
|
|
993
967
|
: fallbackResult;
|
|
994
968
|
}, function () { return fallbackResult; });
|
|
995
969
|
var restart = React__namespace.useCallback(function () {
|
|
996
|
-
globals.invariant(!optionsRef.current.skip,
|
|
970
|
+
globals.invariant(!optionsRef.current.skip, 88);
|
|
997
971
|
setObservable(recreateRef.current());
|
|
998
972
|
}, [optionsRef, recreateRef]);
|
|
999
973
|
return React__namespace.useMemo(function () { return (tslib.__assign(tslib.__assign({}, ret), { restart: restart })); }, [ret, restart]);
|
|
@@ -1064,7 +1038,7 @@ function useFragment_(options) {
|
|
|
1064
1038
|
};
|
|
1065
1039
|
}
|
|
1066
1040
|
var cache = client.cache;
|
|
1067
|
-
var diff = muteDeprecations("canonizeResults", function () {
|
|
1041
|
+
var diff = utilities.muteDeprecations("canonizeResults", function () {
|
|
1068
1042
|
return cache.diff(tslib.__assign(tslib.__assign({}, stableOptions), { returnPartialData: true, id: from, query: cache["getFragmentDoc"](fragment, fragmentName), optimistic: optimistic }));
|
|
1069
1043
|
});
|
|
1070
1044
|
return {
|
|
@@ -1078,7 +1052,7 @@ function useFragment_(options) {
|
|
|
1078
1052
|
var getSnapshot = React__namespace.useCallback(function () { return diff.result; }, [diff]);
|
|
1079
1053
|
return useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
|
|
1080
1054
|
var lastTimeout = 0;
|
|
1081
|
-
var subscription = muteDeprecations("canonizeResults", function () {
|
|
1055
|
+
var subscription = utilities.muteDeprecations("canonizeResults", function () {
|
|
1082
1056
|
return stableOptions.from === null ?
|
|
1083
1057
|
null
|
|
1084
1058
|
: client.watchFragment(stableOptions).subscribe({
|
|
@@ -1132,7 +1106,7 @@ function useSuspenseQuery_(query, options) {
|
|
|
1132
1106
|
query,
|
|
1133
1107
|
cache.canonicalStringify(variables)
|
|
1134
1108
|
], [].concat(queryKey), true);
|
|
1135
|
-
var queryRef = muteDeprecations("canonizeResults", function () {
|
|
1109
|
+
var queryRef = utilities.muteDeprecations("canonizeResults", function () {
|
|
1136
1110
|
return suspenseCache.getQueryRef(cacheKey, function () {
|
|
1137
1111
|
return client.watchQuery(watchQueryOptions);
|
|
1138
1112
|
});
|
|
@@ -1204,11 +1178,11 @@ function validateFetchPolicy(fetchPolicy) {
|
|
|
1204
1178
|
"no-cache",
|
|
1205
1179
|
"cache-and-network",
|
|
1206
1180
|
];
|
|
1207
|
-
globals.invariant(supportedFetchPolicies.includes(fetchPolicy),
|
|
1181
|
+
globals.invariant(supportedFetchPolicies.includes(fetchPolicy), 89, fetchPolicy);
|
|
1208
1182
|
}
|
|
1209
1183
|
function validatePartialDataReturn(fetchPolicy, returnPartialData) {
|
|
1210
1184
|
if (fetchPolicy === "no-cache" && returnPartialData) {
|
|
1211
|
-
globalThis.__DEV__ !== false && globals.invariant.warn(
|
|
1185
|
+
globalThis.__DEV__ !== false && globals.invariant.warn(90);
|
|
1212
1186
|
}
|
|
1213
1187
|
}
|
|
1214
1188
|
function toApolloError(result) {
|
|
@@ -1257,7 +1231,7 @@ function useBackgroundQuery_(query, options) {
|
|
|
1257
1231
|
query,
|
|
1258
1232
|
cache.canonicalStringify(variables)
|
|
1259
1233
|
], [].concat(queryKey), true);
|
|
1260
|
-
var queryRef = muteDeprecations("canonizeResults", function () {
|
|
1234
|
+
var queryRef = utilities.muteDeprecations("canonizeResults", function () {
|
|
1261
1235
|
return suspenseCache.getQueryRef(cacheKey, function () {
|
|
1262
1236
|
return client.watchQuery(watchQueryOptions);
|
|
1263
1237
|
});
|
|
@@ -1378,13 +1352,13 @@ function useLoadableQuery(query, options) {
|
|
|
1378
1352
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1379
1353
|
args[_i] = arguments[_i];
|
|
1380
1354
|
}
|
|
1381
|
-
globals.invariant(!calledDuringRender(),
|
|
1355
|
+
globals.invariant(!calledDuringRender(), 81);
|
|
1382
1356
|
var variables = args[0];
|
|
1383
1357
|
var cacheKey = tslib.__spreadArray([
|
|
1384
1358
|
query,
|
|
1385
1359
|
cache.canonicalStringify(variables)
|
|
1386
1360
|
], [].concat(queryKey), true);
|
|
1387
|
-
var queryRef = muteDeprecations("canonizeResults", function () {
|
|
1361
|
+
var queryRef = utilities.muteDeprecations("canonizeResults", function () {
|
|
1388
1362
|
return suspenseCache.getQueryRef(cacheKey, function () {
|
|
1389
1363
|
return client.watchQuery(tslib.__assign(tslib.__assign({}, watchQueryOptions), { variables: variables }));
|
|
1390
1364
|
});
|
|
@@ -1399,7 +1373,7 @@ function useLoadableQuery(query, options) {
|
|
|
1399
1373
|
client,
|
|
1400
1374
|
]);
|
|
1401
1375
|
var subscribeToMore = React__namespace.useCallback(function (options) {
|
|
1402
|
-
globals.invariant(internalQueryRef,
|
|
1376
|
+
globals.invariant(internalQueryRef, 82);
|
|
1403
1377
|
return internalQueryRef.observable.subscribeToMore(
|
|
1404
1378
|
options);
|
|
1405
1379
|
}, [internalQueryRef]);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { DeprecationName } from "../../../utilities/
|
|
1
|
+
import type { DeprecationName } from "../../../utilities/index.js";
|
|
2
2
|
export declare function useWarnRemoved(name: DeprecationName, cb: () => void): void;
|
|
3
3
|
//# sourceMappingURL=useWarnRemoved.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "rehackt";
|
|
2
|
-
import { warnDeprecated } from "../../../utilities/
|
|
2
|
+
import { warnDeprecated } from "../../../utilities/index.js";
|
|
3
3
|
export function useWarnRemoved(name, cb) {
|
|
4
4
|
"use no memo";
|
|
5
5
|
var didWarn = React.useRef(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWarnRemoved.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useWarnRemoved.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useWarnRemoved.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useWarnRemoved.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAE7D,MAAM,UAAU,cAAc,CAAC,IAAqB,EAAE,EAAc;IAClE,aAAa,CAAC;IACd,IAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEpC,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACrB,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC3B,CAAC;QAED,yDAAyD;QACzD,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IACzB,CAAC;AACH,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DeprecationName } from \"../../../utilities/index.js\";\nimport { warnDeprecated } from \"../../../utilities/index.js\";\n\nexport function useWarnRemoved(name: DeprecationName, cb: () => void) {\n \"use no memo\";\n const didWarn = React.useRef(false);\n\n if (__DEV__) {\n if (!didWarn.current) {\n warnDeprecated(name, cb);\n }\n\n // eslint-disable-next-line react-compiler/react-compiler\n didWarn.current = true;\n }\n}\n"]}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { PossibleDeprecations } from "../../../utilities/index.js";
|
|
2
|
+
export declare function useWarnRemovedOption<TOptions extends Record<string, any>, CallSite extends keyof PossibleDeprecations>(options: TOptions, name: keyof TOptions & PossibleDeprecations[CallSite][number], callSite: CallSite, recommendation?: string): void;
|
|
2
3
|
//# sourceMappingURL=useWarnRemovedOption.d.ts.map
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import * as React from "rehackt";
|
|
2
|
-
import {
|
|
2
|
+
import { warnRemovedOption } from "../../../utilities/index.js";
|
|
3
3
|
// Remove with Apollo Client 4.0
|
|
4
4
|
export function useWarnRemovedOption(options, name, callSite, recommendation) {
|
|
5
5
|
"use no memo";
|
|
6
6
|
if (recommendation === void 0) { recommendation = "Please remove this option."; }
|
|
7
7
|
var didWarn = React.useRef(false);
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
if (globalThis.__DEV__ !== false) {
|
|
9
|
+
if (name in options && !didWarn.current) {
|
|
10
|
+
warnRemovedOption(options, name, callSite, recommendation);
|
|
11
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
12
|
+
didWarn.current = true;
|
|
13
|
+
}
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=useWarnRemovedOption.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWarnRemovedOption.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useWarnRemovedOption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"useWarnRemovedOption.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useWarnRemovedOption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,gCAAgC;AAChC,MAAM,UAAU,oBAAoB,CAIlC,OAAiB,EACjB,IAA6D,EAC7D,QAAkB,EAClB,cAAqD;IAErD,aAAa,CAAC;IAFd,+BAAA,EAAA,6CAAqD;IAGrD,IAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEpC,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACxC,iBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;YAE3D,yDAAyD;YACzD,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { PossibleDeprecations } from \"../../../utilities/index.js\";\nimport { warnRemovedOption } from \"../../../utilities/index.js\";\n\n// Remove with Apollo Client 4.0\nexport function useWarnRemovedOption<\n TOptions extends Record<string, any>,\n CallSite extends keyof PossibleDeprecations,\n>(\n options: TOptions,\n name: keyof TOptions & PossibleDeprecations[CallSite][number],\n callSite: CallSite,\n recommendation: string = \"Please remove this option.\"\n) {\n \"use no memo\";\n const didWarn = React.useRef(false);\n\n if (__DEV__) {\n if (name in options && !didWarn.current) {\n warnRemovedOption(options, name, callSite, recommendation);\n\n // eslint-disable-next-line react-compiler/react-compiler\n didWarn.current = true;\n }\n }\n}\n"]}
|
|
@@ -19,7 +19,7 @@ import { getApolloContext } from "../context/index.js";
|
|
|
19
19
|
export function useApolloClient(override) {
|
|
20
20
|
var context = React.useContext(getApolloContext());
|
|
21
21
|
var client = override || context.client;
|
|
22
|
-
invariant(!!client,
|
|
22
|
+
invariant(!!client, 78);
|
|
23
23
|
return client;
|
|
24
24
|
}
|
|
25
25
|
//# sourceMappingURL=useApolloClient.js.map
|
|
@@ -5,7 +5,7 @@ import { getSuspenseCache, unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef,
|
|
|
5
5
|
import { useWarnRemovedOption, wrapHook } from "./internal/index.js";
|
|
6
6
|
import { useWatchQueryOptions } from "./useSuspenseQuery.js";
|
|
7
7
|
import { canonicalStringify } from "../../cache/index.js";
|
|
8
|
-
import { muteDeprecations } from "../../utilities/
|
|
8
|
+
import { muteDeprecations } from "../../utilities/index.js";
|
|
9
9
|
export function useBackgroundQuery(query, options) {
|
|
10
10
|
if (options === void 0) { options = Object.create(null); }
|
|
11
11
|
return wrapHook("useBackgroundQuery",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AASjC,OAAO,EAAE,eAA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FetchMoreQueryOptions,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport type { SubscribeToMoreFunction } from \"../../core/watchQueryOptions.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../internal/index.js\";\nimport type { CacheKey, QueryRef } from \"../internal/index.js\";\nimport type { BackgroundQueryHookOptions, NoInfer } from \"../types/types.js\";\nimport { useWarnRemovedOption, wrapHook } from \"./internal/index.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\nimport type { FetchMoreFunction, RefetchFunction } from \"./useSuspenseQuery.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport type { SkipToken } from \"./constants.js\";\nimport { muteDeprecations } from \"../../utilities/deprecation/index.js\";\n\nexport type UseBackgroundQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)} */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#refetch:member(1)} */\n refetch: RefetchFunction<TData, TVariables>;\n};\n\ntype BackgroundQueryHookOptionsNoInfer<\n TData,\n TVariables extends OperationVariables,\n> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;\n\nexport function useBackgroundQuery<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit<BackgroundQueryHookOptions<TData>, \"variables\">,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions\n): [\n (\n | QueryRef<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\" ?\n TOptions[\"returnPartialData\"] extends true ?\n DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true ? DeepPartial<TData>\n : TData,\n TVariables\n >\n | (TOptions[\"skip\"] extends boolean ? undefined : never)\n ),\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<DeepPartial<TData> | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n returnPartialData: true;\n }\n): [\n QueryRef<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n }\n): [\n QueryRef<DeepPartial<TData>, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n }\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [QueryRef<TData, TVariables>, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n })\n): [\n QueryRef<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables> = Object.create(null)\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n return wrapHook(\n \"useBackgroundQuery\",\n // eslint-disable-next-line react-compiler/react-compiler\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options);\n}\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n if (__DEV__) {\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useWarnRemovedOption(\n typeof options === \"symbol\" ? {} : options,\n \"canonizeResults\",\n \"useBackgroundQuery\"\n );\n }\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = muteDeprecations(\"canonizeResults\", () =>\n suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions as WatchQueryOptions<any, any>)\n )\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options as FetchMoreQueryOptions<any>);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n subscribeToMore: queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData, TVariables>,\n },\n ];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AASjC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,q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ACxC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,cAAM,OAAA,YAAY,CAAC,EAAE,CAAC,EAAhB,CAAgB,CAAC;QAC9B,uEAAuE;QACvE,kEAAkE;IACpE,CAAC,CAAC,CAAC;IAEH,IAAM,SAAS,GAAyC,KAAK,CAAC,WAAW,CACvE,UAAC,OAAO;QACN,IAAM,OAAO,GAAG,QAAQ,CAAC,SAAS,CAAC,OAAqC,CAAC,CAAC;QAE1E,kBAAkB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE3C,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,IAAM,OAAO,GAAuC,KAAK,CAAC,WAAW,CACnE,UAAC,SAAS;QACR,IAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAE5C,kBAAkB,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC;QAE3C,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,cAAM,OAAA,QAAQ,CAAC,UAAU,EAAE,EAArB,CAAqB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEzD,OAAO;QACL,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC;QACjD;YACE,SAAS,WAAA;YACT,OAAO,SAAA;YACP,kGAAkG;YAClG,eAAe,EAAE,QAAQ,CAAC,UAAU;iBACjC,eAA6D;SACjE;KACF,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type {\n DocumentNode,\n FetchMoreQueryOptions,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport type { SubscribeToMoreFunction } from \"../../core/watchQueryOptions.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../internal/index.js\";\nimport type { CacheKey, QueryRef } from \"../internal/index.js\";\nimport type { BackgroundQueryHookOptions, NoInfer } from \"../types/types.js\";\nimport { useWarnRemovedOption, wrapHook } from \"./internal/index.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\nimport type { FetchMoreFunction, RefetchFunction } from \"./useSuspenseQuery.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport type { SkipToken } from \"./constants.js\";\nimport { muteDeprecations } from \"../../utilities/index.js\";\n\nexport type UseBackgroundQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)} */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#refetch:member(1)} */\n refetch: RefetchFunction<TData, TVariables>;\n};\n\ntype BackgroundQueryHookOptionsNoInfer<\n TData,\n TVariables extends OperationVariables,\n> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;\n\nexport function useBackgroundQuery<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit<BackgroundQueryHookOptions<TData>, \"variables\">,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions\n): [\n (\n | QueryRef<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\" ?\n TOptions[\"returnPartialData\"] extends true ?\n DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true ? DeepPartial<TData>\n : TData,\n TVariables\n >\n | (TOptions[\"skip\"] extends boolean ? undefined : never)\n ),\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<DeepPartial<TData> | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n returnPartialData: true;\n }\n): [\n QueryRef<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n }\n): [\n QueryRef<DeepPartial<TData>, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n }\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [QueryRef<TData, TVariables>, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n })\n): [\n QueryRef<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables> = Object.create(null)\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n return wrapHook(\n \"useBackgroundQuery\",\n // eslint-disable-next-line react-compiler/react-compiler\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options);\n}\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n if (__DEV__) {\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useWarnRemovedOption(\n typeof options === \"symbol\" ? {} : options,\n \"canonizeResults\",\n \"useBackgroundQuery\"\n );\n }\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = muteDeprecations(\"canonizeResults\", () =>\n suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions as WatchQueryOptions<any, any>)\n )\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options as FetchMoreQueryOptions<any>);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n subscribeToMore: queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData, TVariables>,\n },\n ];\n}\n"]}
|
|
@@ -5,7 +5,7 @@ import { useApolloClient } from "./useApolloClient.js";
|
|
|
5
5
|
import { useSyncExternalStore } from "./useSyncExternalStore.js";
|
|
6
6
|
import { useDeepMemo, useWarnRemovedOption, wrapHook, } from "./internal/index.js";
|
|
7
7
|
import equal from "@wry/equality";
|
|
8
|
-
import { muteDeprecations } from "../../utilities/
|
|
8
|
+
import { muteDeprecations } from "../../utilities/index.js";
|
|
9
9
|
export function useFragment(options) {
|
|
10
10
|
return wrapHook("useFragment",
|
|
11
11
|
// eslint-disable-next-line react-compiler/react-compiler
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC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W,EAAE,CAAC;YAC5B,YAAY,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EACD,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,CAC9B,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,IAAM,MAAM,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,MAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KACE,CAAC;IAE9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport { mergeDeepArray } from \"../../utilities/index.js\";\nimport type {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache/index.js\";\n\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport type { ApolloClient, OperationVariables } from \"../../core/index.js\";\nimport type { NoInfer } from \"../types/types.js\";\nimport {\n useDeepMemo,\n useWarnRemovedOption,\n wrapHook,\n} from \"./internal/index.js\";\nimport equal from \"@wry/equality\";\nimport type { FragmentType, MaybeMasked } from \"../../masking/index.js\";\nimport { muteDeprecations } from \"../../utilities/index.js\";\n\nexport interface UseFragmentOptions<TData, TVars>\n extends Omit<\n Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>,\n \"id\" | \"query\" | \"optimistic\" | \"previousResult\" | \"returnPartialData\"\n >,\n Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n \"id\" | \"variables\" | \"returnPartialData\"\n > {\n from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string | null;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient<any>;\n}\n\nexport type UseFragmentResult<TData> =\n | {\n data: MaybeMasked<TData>;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<MaybeMasked<TData>>;\n complete: false;\n missing?: MissingTree;\n };\n\nexport function useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n return wrapHook(\n \"useFragment\",\n // eslint-disable-next-line react-compiler/react-compiler\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\n if (__DEV__) {\n // eslint-disable-next-line react-compiler/react-compiler, react-hooks/rules-of-hooks\n useWarnRemovedOption(options, \"canonizeResults\", \"useFragment\");\n }\n const client = useApolloClient(options.client);\n const { cache } = client;\n const { from, ...rest } = options;\n\n // We calculate the cache id seperately from `stableOptions` because we don't\n // want changes to non key fields in the `from` property to affect\n // `stableOptions` and retrigger our subscription. If the cache identifier\n // stays the same between renders, we want to reuse the existing subscription.\n const id = React.useMemo(\n () =>\n typeof from === \"string\" ? from\n : from === null ? null\n : cache.identify(from),\n [cache, from]\n );\n\n const stableOptions = useDeepMemo(() => ({ ...rest, from: id! }), [rest, id]);\n\n // Since .next is async, we need to make sure that we\n // get the correct diff on the next render given new diffOptions\n const diff = React.useMemo(() => {\n const { fragment, fragmentName, from, optimistic = true } = stableOptions;\n\n if (from === null) {\n return {\n result: diffToResult({\n result: {} as TData,\n complete: false,\n }),\n };\n }\n\n const { cache } = client;\n const diff = muteDeprecations(\"canonizeResults\", () =>\n cache.diff<TData>({\n ...stableOptions,\n returnPartialData: true,\n id: from,\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n })\n );\n\n return {\n result: diffToResult({\n ...diff,\n result: client[\"queryManager\"].maskFragment({\n fragment,\n fragmentName,\n data: diff.result,\n }),\n }),\n };\n }, [client, stableOptions]);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = React.useCallback(() => diff.result, [diff]);\n\n return useSyncExternalStore(\n React.useCallback(\n (forceUpdate) => {\n let lastTimeout = 0;\n\n const subscription = muteDeprecations(\"canonizeResults\", () =>\n stableOptions.from === null ?\n null\n : client.watchFragment(stableOptions).subscribe({\n next: (result) => {\n // Since `next` is called async by zen-observable, we want to avoid\n // unnecessarily rerendering this hook for the initial result\n // emitted from watchFragment which should be equal to\n // `diff.result`.\n if (equal(result, diff.result)) return;\n diff.result = result;\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(forceUpdate) as any;\n },\n })\n );\n return () => {\n subscription?.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [client, stableOptions, diff]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): UseFragmentResult<TData> {\n const result = {\n data: diff.result!,\n complete: !!diff.complete,\n } as UseFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(diff.missing.map((error) => error.missing));\n }\n\n return result;\n}\n"]}
|
|
@@ -5,7 +5,7 @@ import { createMakeWatchQueryOptions, getDefaultFetchPolicy, getObsQueryOptions,
|
|
|
5
5
|
import { useIsomorphicLayoutEffect } from "./internal/useIsomorphicLayoutEffect.js";
|
|
6
6
|
import { useWarnRemovedOption } from "./internal/useWarnRemovedOption.js";
|
|
7
7
|
import { invariant } from "../../utilities/globals/invariantWrappers.js";
|
|
8
|
-
import { warnRemovedOption } from "../../utilities/
|
|
8
|
+
import { warnRemovedOption } from "../../utilities/index.js";
|
|
9
9
|
import { useRenderGuard } from "./internal/index.js";
|
|
10
10
|
// The following methods, when called will execute the query, regardless of
|
|
11
11
|
// whether the useLazyQuery execute function was called before.
|
|
@@ -111,7 +111,7 @@ export function useLazyQuery(query, options) {
|
|
|
111
111
|
eagerMethods[key] = function () {
|
|
112
112
|
if (globalThis.__DEV__ !== false) {
|
|
113
113
|
if (key === "reobserve") {
|
|
114
|
-
globalThis.__DEV__ !== false && invariant.warn(
|
|
114
|
+
globalThis.__DEV__ !== false && invariant.warn(79);
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
if (!execOptionsRef.current) {
|
|
@@ -136,7 +136,7 @@ export function useLazyQuery(query, options) {
|
|
|
136
136
|
var execute = React.useCallback(function (executeOptions) {
|
|
137
137
|
if (globalThis.__DEV__ !== false) {
|
|
138
138
|
if (calledDuringRender()) {
|
|
139
|
-
globalThis.__DEV__ !== false && invariant.warn(
|
|
139
|
+
globalThis.__DEV__ !== false && invariant.warn(80);
|
|
140
140
|
}
|
|
141
141
|
for (var _i = 0, REMOVED_EXECUTE_OPTIONS_1 = REMOVED_EXECUTE_OPTIONS; _i < REMOVED_EXECUTE_OPTIONS_1.length; _i++) {
|
|
142
142
|
var name_1 = REMOVED_EXECUTE_OPTIONS_1[_i];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AASjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAUxD,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAA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AM,EAAE,OAAO,EAAE,iBAAiB,CAAC,CACnE,CAAC;IACF,eAAe,CAAC,iBAAiB,CAAC,CAAC;IAEnC,OAAO,IAAI,OAAO,CAEhB,UAAC,OAAO;QACR,IAAI,MAAgC,CAAC;QAErC,wEAAwE;QACxE,0EAA0E;QAC1E,yEAAyE;QACzE,iDAAiD;QACjD,OAAO,CAAC,SAAS,CAAC;YAChB,IAAI,EAAE,UAAC,KAAK;gBACV,MAAM,GAAG,KAAK,CAAC;YACjB,CAAC;YACD,KAAK,EAAE;gBACL,OAAO,CACL,aAAa,CACX,UAAU,CAAC,gBAAgB,EAAE,EAC7B,UAAU,CAAC,YAAY,EACvB,UAAU,EACV,MAAM,CACP,CACF,CAAC;YACJ,CAAC;YACD,QAAQ,EAAE;gBACR,OAAO,CACL,aAAa,CACX,UAAU,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAChC,UAAU,CAAC,YAAY,EACvB,UAAU,EACV,MAAM,CACP,CACF,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport * as React from \"rehackt\";\n\nimport type {\n ApolloClient,\n ApolloQueryResult,\n ObservableQuery,\n OperationVariables,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport type {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryHookOptions,\n QueryResult,\n} from \"../types/types.js\";\nimport type { InternalResult } from \"./useQuery.js\";\nimport {\n createMakeWatchQueryOptions,\n getDefaultFetchPolicy,\n getObsQueryOptions,\n toQueryResult,\n useQueryInternals,\n} from \"./useQuery.js\";\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\nimport { useWarnRemovedOption } from \"./internal/useWarnRemovedOption.js\";\nimport { invariant } from \"../../utilities/globals/invariantWrappers.js\";\nimport { warnRemovedOption } from \"../../utilities/deprecation/index.js\";\nimport { useRenderGuard } from \"./internal/index.js\";\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 \"stopPolling\",\n \"subscribeToMore\",\n] as const;\n\nconst REMOVED_EXECUTE_OPTIONS = [\n \"initialFetchPolicy\",\n \"onCompleted\",\n \"onError\",\n \"defaultOptions\",\n \"partialRefetch\",\n \"canonizeResults\",\n] as const satisfies Array<keyof LazyQueryHookExecOptions>;\n\nconst DEPRECATED_EXECUTE_OPTIONS = [\n \"query\",\n \"ssr\",\n \"client\",\n \"fetchPolicy\",\n \"nextFetchPolicy\",\n \"refetchWritePolicy\",\n \"errorPolicy\",\n \"pollInterval\",\n \"notifyOnNetworkStatusChange\",\n \"returnPartialData\",\n \"skipPollAttempt\",\n] as const satisfies Array<\n Exclude<\n keyof LazyQueryHookExecOptions,\n (typeof REMOVED_EXECUTE_OPTIONS)[number]\n >\n>;\n\n/**\n * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.\n *\n * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.\n *\n * @example\n * ```jsx\n * import { gql, useLazyQuery } from \"@apollo/client\";\n *\n * const GET_GREETING = gql`\n * query GetGreeting($language: String!) {\n * greeting(language: $language) {\n * message\n * }\n * }\n * `;\n *\n * function Hello() {\n * const [loadGreeting, { called, loading, data }] = useLazyQuery(\n * GET_GREETING,\n * { variables: { language: \"english\" } }\n * );\n * if (called && loading) return <p>Loading ...</p>\n * if (!called) {\n * return <button onClick={() => loadGreeting()}>Load greeting</button>\n * }\n * return <h1>Hello {data.greeting.message}!</h1>;\n * }\n * ```\n * @since 3.0.0\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - Default options to control how the query is executed.\n * @returns A tuple in the form of `[execute, result]`\n */\nexport function useLazyQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n if (__DEV__) {\n /* eslint-disable react-hooks/rules-of-hooks, react-compiler/react-compiler */\n const warnOpts = options || {};\n\n useWarnRemovedOption(warnOpts, \"canonizeResults\", \"useLazyQuery\");\n useWarnRemovedOption(\n warnOpts,\n \"variables\",\n \"useLazyQuery\",\n \"Pass all `variables` to the returned `execute` function instead.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"context\",\n \"useLazyQuery\",\n \"Pass `context` to the returned `execute` function instead.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"onCompleted\",\n \"useLazyQuery\",\n \"If your `onCompleted` callback sets local state, switch to use derived state using `data` returned from the hook instead. Use `useEffect` to perform side-effects as a result of updates to `data`.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"onError\",\n \"useLazyQuery\",\n \"If your `onError` callback sets local state, switch to use derived state using `data`, `error` or `errors` returned from the hook instead. Use `useEffect` if you need to perform side-effects as a result of updates to `data`, `error` or `errors`.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"defaultOptions\",\n \"useLazyQuery\",\n \"Pass the options directly to the hook instead.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"initialFetchPolicy\",\n \"useLazyQuery\",\n \"Use the `fetchPolicy` option instead.\"\n );\n\n useWarnRemovedOption(warnOpts, \"partialRefetch\", \"useLazyQuery\");\n /* eslint-enable react-hooks/rules-of-hooks, react-compiler/react-compiler */\n }\n\n const execOptionsRef =\n React.useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>(void 0);\n const optionsRef =\n React.useRef<LazyQueryHookOptions<TData, TVariables>>(void 0);\n const queryRef = React.useRef<\n DocumentNode | TypedDocumentNode<TData, TVariables>\n >(void 0);\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 = options;\n queryRef.current = document;\n\n const queryHookOptions = {\n ...merged,\n skip: !execOptionsRef.current,\n };\n const {\n obsQueryFields,\n result: useQueryResult,\n client,\n resultData,\n observable,\n onQueryExecuted,\n } = useQueryInternals(document, queryHookOptions);\n\n const initialFetchPolicy =\n observable.options.initialFetchPolicy ||\n getDefaultFetchPolicy(\n queryHookOptions.defaultOptions,\n client.defaultOptions\n );\n\n const forceUpdateState = React.useReducer((tick) => tick + 1, 0)[1];\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = React.useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = obsQueryFields[key];\n eagerMethods[key] = function () {\n if (__DEV__) {\n if (key === \"reobserve\") {\n invariant.warn(\n \"[useLazyQuery]: `reobserve` is deprecated and will removed in Apollo Client 4.0. Please change options by rerendering `useLazyQuery` with new options.\"\n );\n }\n }\n\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n forceUpdateState();\n }\n // @ts-expect-error this is just too generic to type\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods as typeof obsQueryFields;\n }, [forceUpdateState, obsQueryFields]);\n\n const called = !!execOptionsRef.current;\n const result = React.useMemo(\n () => ({\n ...useQueryResult,\n ...eagerMethods,\n called,\n }),\n [useQueryResult, eagerMethods, called]\n );\n\n const calledDuringRender = useRenderGuard();\n const warnRef = React.useRef(new Set<keyof LazyQueryHookExecOptions>());\n\n const execute = React.useCallback<LazyQueryResultTuple<TData, TVariables>[0]>(\n (executeOptions) => {\n if (__DEV__) {\n if (calledDuringRender()) {\n invariant.warn(\n \"[useLazyQuery]: Calling `execute` in render will throw in Apollo Client 4.0. Either switch to `useQuery` to run the query during render or move the `execute` call inside of `useEffect`.\"\n );\n }\n\n for (const name of REMOVED_EXECUTE_OPTIONS) {\n if (!warnRef.current.has(name)) {\n warnRemovedOption(\n executeOptions || {},\n name,\n \"useLazyQuery.execute\"\n );\n warnRef.current.add(name);\n }\n }\n\n for (const name of DEPRECATED_EXECUTE_OPTIONS) {\n if (!warnRef.current.has(name)) {\n warnRemovedOption(\n executeOptions || {},\n name,\n \"useLazyQuery.execute\",\n \"Please pass the option to the `useLazyQuery` hook instead.\"\n );\n warnRef.current.add(name);\n }\n }\n }\n\n execOptionsRef.current =\n executeOptions ?\n {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n }\n : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const options = mergeOptions(optionsRef.current, {\n query: queryRef.current,\n ...execOptionsRef.current,\n });\n\n const promise = executeQuery(\n resultData,\n observable,\n client,\n document,\n { ...options, skip: false },\n onQueryExecuted\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 calledDuringRender,\n client,\n document,\n eagerMethods,\n initialFetchPolicy,\n observable,\n resultData,\n onQueryExecuted,\n ]\n );\n\n const executeRef = React.useRef(execute);\n useIsomorphicLayoutEffect(() => {\n executeRef.current = execute;\n });\n\n const stableExecute = React.useCallback<typeof execute>(\n (...args) => executeRef.current(...args),\n []\n );\n return [stableExecute, result];\n}\n\nfunction executeQuery<TData, TVariables extends OperationVariables>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n currentQuery: DocumentNode,\n options: QueryHookOptions<TData, TVariables> & {\n query?: DocumentNode;\n },\n onQueryExecuted: (options: WatchQueryOptions<TVariables, TData>) => void\n) {\n const query = options.query || currentQuery;\n const watchQueryOptions = createMakeWatchQueryOptions(\n client,\n query,\n options,\n false\n )(observable);\n\n const concast = observable.reobserveAsConcast(\n getObsQueryOptions(observable, client, options, watchQueryOptions)\n );\n onQueryExecuted(watchQueryOptions);\n\n return new Promise<\n Omit<QueryResult<TData, TVariables>, (typeof EAGER_METHODS)[number]>\n >((resolve) => {\n let result: ApolloQueryResult<TData>;\n\n // Subscribe to the concast independently of the ObservableQuery in case\n // the component gets unmounted before the promise resolves. This prevents\n // the concast from terminating early and resolving with `undefined` when\n // there are no more subscribers for the concast.\n concast.subscribe({\n next: (value) => {\n result = value;\n },\n error: () => {\n resolve(\n toQueryResult(\n observable.getCurrentResult(),\n resultData.previousData,\n observable,\n client\n )\n );\n },\n complete: () => {\n resolve(\n toQueryResult(\n observable[\"maskResult\"](result),\n resultData.previousData,\n observable,\n client\n )\n );\n },\n });\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AASjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAUxD,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,2EAA2E;AAC3E,+DAA+D;AAC/D,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,aAAa;IACb,iBAAiB;CACT,CAAC;AAEX,IAAM,uBAAuB,GAAG;IAC9B,oBA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CACX,UAAU,CAAC,gBAAgB,EAAE,EAC7B,UAAU,CAAC,YAAY,EACvB,UAAU,EACV,MAAM,CACP,CACF,CAAC;YACJ,CAAC;YACD,QAAQ,EAAE;gBACR,OAAO,CACL,aAAa,CACX,UAAU,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAChC,UAAU,CAAC,YAAY,EACvB,UAAU,EACV,MAAM,CACP,CACF,CAAC;YACJ,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport * as React from \"rehackt\";\n\nimport type {\n ApolloClient,\n ApolloQueryResult,\n ObservableQuery,\n OperationVariables,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport type {\n LazyQueryHookExecOptions,\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n NoInfer,\n QueryHookOptions,\n QueryResult,\n} from \"../types/types.js\";\nimport type { InternalResult } from \"./useQuery.js\";\nimport {\n createMakeWatchQueryOptions,\n getDefaultFetchPolicy,\n getObsQueryOptions,\n toQueryResult,\n useQueryInternals,\n} from \"./useQuery.js\";\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\nimport { useWarnRemovedOption } from \"./internal/useWarnRemovedOption.js\";\nimport { invariant } from \"../../utilities/globals/invariantWrappers.js\";\nimport { warnRemovedOption } from \"../../utilities/index.js\";\nimport { useRenderGuard } from \"./internal/index.js\";\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 \"stopPolling\",\n \"subscribeToMore\",\n] as const;\n\nconst REMOVED_EXECUTE_OPTIONS = [\n \"initialFetchPolicy\",\n \"onCompleted\",\n \"onError\",\n \"defaultOptions\",\n \"partialRefetch\",\n \"canonizeResults\",\n] as const satisfies Array<keyof LazyQueryHookExecOptions>;\n\nconst DEPRECATED_EXECUTE_OPTIONS = [\n \"query\",\n \"ssr\",\n \"client\",\n \"fetchPolicy\",\n \"nextFetchPolicy\",\n \"refetchWritePolicy\",\n \"errorPolicy\",\n \"pollInterval\",\n \"notifyOnNetworkStatusChange\",\n \"returnPartialData\",\n \"skipPollAttempt\",\n] as const satisfies Array<\n Exclude<\n keyof LazyQueryHookExecOptions,\n (typeof REMOVED_EXECUTE_OPTIONS)[number]\n >\n>;\n\n/**\n * A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.\n *\n * > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.\n *\n * @example\n * ```jsx\n * import { gql, useLazyQuery } from \"@apollo/client\";\n *\n * const GET_GREETING = gql`\n * query GetGreeting($language: String!) {\n * greeting(language: $language) {\n * message\n * }\n * }\n * `;\n *\n * function Hello() {\n * const [loadGreeting, { called, loading, data }] = useLazyQuery(\n * GET_GREETING,\n * { variables: { language: \"english\" } }\n * );\n * if (called && loading) return <p>Loading ...</p>\n * if (!called) {\n * return <button onClick={() => loadGreeting()}>Load greeting</button>\n * }\n * return <h1>Hello {data.greeting.message}!</h1>;\n * }\n * ```\n * @since 3.0.0\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - Default options to control how the query is executed.\n * @returns A tuple in the form of `[execute, result]`\n */\nexport function useLazyQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): LazyQueryResultTuple<TData, TVariables> {\n if (__DEV__) {\n /* eslint-disable react-hooks/rules-of-hooks, react-compiler/react-compiler */\n const warnOpts = options || {};\n\n useWarnRemovedOption(warnOpts, \"canonizeResults\", \"useLazyQuery\");\n useWarnRemovedOption(\n warnOpts,\n \"variables\",\n \"useLazyQuery\",\n \"Pass all `variables` to the returned `execute` function instead.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"context\",\n \"useLazyQuery\",\n \"Pass `context` to the returned `execute` function instead.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"onCompleted\",\n \"useLazyQuery\",\n \"If your `onCompleted` callback sets local state, switch to use derived state using `data` returned from the hook instead. Use `useEffect` to perform side-effects as a result of updates to `data`.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"onError\",\n \"useLazyQuery\",\n \"If your `onError` callback sets local state, switch to use derived state using `data`, `error` or `errors` returned from the hook instead. Use `useEffect` if you need to perform side-effects as a result of updates to `data`, `error` or `errors`.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"defaultOptions\",\n \"useLazyQuery\",\n \"Pass the options directly to the hook instead.\"\n );\n useWarnRemovedOption(\n warnOpts,\n \"initialFetchPolicy\",\n \"useLazyQuery\",\n \"Use the `fetchPolicy` option instead.\"\n );\n\n useWarnRemovedOption(warnOpts, \"partialRefetch\", \"useLazyQuery\");\n /* eslint-enable react-hooks/rules-of-hooks, react-compiler/react-compiler */\n }\n\n const execOptionsRef =\n React.useRef<Partial<LazyQueryHookExecOptions<TData, TVariables>>>(void 0);\n const optionsRef =\n React.useRef<LazyQueryHookOptions<TData, TVariables>>(void 0);\n const queryRef = React.useRef<\n DocumentNode | TypedDocumentNode<TData, TVariables>\n >(void 0);\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 = options;\n queryRef.current = document;\n\n const queryHookOptions = {\n ...merged,\n skip: !execOptionsRef.current,\n };\n const {\n obsQueryFields,\n result: useQueryResult,\n client,\n resultData,\n observable,\n onQueryExecuted,\n } = useQueryInternals(document, queryHookOptions);\n\n const initialFetchPolicy =\n observable.options.initialFetchPolicy ||\n getDefaultFetchPolicy(\n queryHookOptions.defaultOptions,\n client.defaultOptions\n );\n\n const forceUpdateState = React.useReducer((tick) => tick + 1, 0)[1];\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = React.useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = obsQueryFields[key];\n eagerMethods[key] = function () {\n if (__DEV__) {\n if (key === \"reobserve\") {\n invariant.warn(\n \"[useLazyQuery]: `reobserve` is deprecated and will removed in Apollo Client 4.0. Please change options by rerendering `useLazyQuery` with new options.\"\n );\n }\n }\n\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n forceUpdateState();\n }\n // @ts-expect-error this is just too generic to type\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods as typeof obsQueryFields;\n }, [forceUpdateState, obsQueryFields]);\n\n const called = !!execOptionsRef.current;\n const result = React.useMemo(\n () => ({\n ...useQueryResult,\n ...eagerMethods,\n called,\n }),\n [useQueryResult, eagerMethods, called]\n );\n\n const calledDuringRender = useRenderGuard();\n const warnRef = React.useRef(new Set<keyof LazyQueryHookExecOptions>());\n\n const execute = React.useCallback<LazyQueryResultTuple<TData, TVariables>[0]>(\n (executeOptions) => {\n if (__DEV__) {\n if (calledDuringRender()) {\n invariant.warn(\n \"[useLazyQuery]: Calling `execute` in render will throw in Apollo Client 4.0. Either switch to `useQuery` to run the query during render or move the `execute` call inside of `useEffect`.\"\n );\n }\n\n for (const name of REMOVED_EXECUTE_OPTIONS) {\n if (!warnRef.current.has(name)) {\n warnRemovedOption(\n executeOptions || {},\n name,\n \"useLazyQuery.execute\"\n );\n warnRef.current.add(name);\n }\n }\n\n for (const name of DEPRECATED_EXECUTE_OPTIONS) {\n if (!warnRef.current.has(name)) {\n warnRemovedOption(\n executeOptions || {},\n name,\n \"useLazyQuery.execute\",\n \"Please pass the option to the `useLazyQuery` hook instead.\"\n );\n warnRef.current.add(name);\n }\n }\n }\n\n execOptionsRef.current =\n executeOptions ?\n {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n }\n : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const options = mergeOptions(optionsRef.current, {\n query: queryRef.current,\n ...execOptionsRef.current,\n });\n\n const promise = executeQuery(\n resultData,\n observable,\n client,\n document,\n { ...options, skip: false },\n onQueryExecuted\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 calledDuringRender,\n client,\n document,\n eagerMethods,\n initialFetchPolicy,\n observable,\n resultData,\n onQueryExecuted,\n ]\n );\n\n const executeRef = React.useRef(execute);\n useIsomorphicLayoutEffect(() => {\n executeRef.current = execute;\n });\n\n const stableExecute = React.useCallback<typeof execute>(\n (...args) => executeRef.current(...args),\n []\n );\n return [stableExecute, result];\n}\n\nfunction executeQuery<TData, TVariables extends OperationVariables>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n currentQuery: DocumentNode,\n options: QueryHookOptions<TData, TVariables> & {\n query?: DocumentNode;\n },\n onQueryExecuted: (options: WatchQueryOptions<TVariables, TData>) => void\n) {\n const query = options.query || currentQuery;\n const watchQueryOptions = createMakeWatchQueryOptions(\n client,\n query,\n options,\n false\n )(observable);\n\n const concast = observable.reobserveAsConcast(\n getObsQueryOptions(observable, client, options, watchQueryOptions)\n );\n onQueryExecuted(watchQueryOptions);\n\n return new Promise<\n Omit<QueryResult<TData, TVariables>, (typeof EAGER_METHODS)[number]>\n >((resolve) => {\n let result: ApolloQueryResult<TData>;\n\n // Subscribe to the concast independently of the ObservableQuery in case\n // the component gets unmounted before the promise resolves. This prevents\n // the concast from terminating early and resolving with `undefined` when\n // there are no more subscribers for the concast.\n concast.subscribe({\n next: (value) => {\n result = value;\n },\n error: () => {\n resolve(\n toQueryResult(\n observable.getCurrentResult(),\n resultData.previousData,\n observable,\n client\n )\n );\n },\n complete: () => {\n resolve(\n toQueryResult(\n observable[\"maskResult\"](result),\n resultData.previousData,\n observable,\n client\n )\n );\n },\n });\n });\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import { useRenderGuard, useWarnRemovedOption, } from "./internal/index.js";
|
|
|
6
6
|
import { useWatchQueryOptions } from "./useSuspenseQuery.js";
|
|
7
7
|
import { canonicalStringify } from "../../cache/index.js";
|
|
8
8
|
import { invariant } from "../../utilities/globals/index.js";
|
|
9
|
-
import { muteDeprecations } from "../../utilities/
|
|
9
|
+
import { muteDeprecations } from "../../utilities/index.js";
|
|
10
10
|
export function useLoadableQuery(query, options) {
|
|
11
11
|
if (options === void 0) { options = Object.create(null); }
|
|
12
12
|
if (globalThis.__DEV__ !== false) {
|
|
@@ -46,7 +46,7 @@ export function useLoadableQuery(query, options) {
|
|
|
46
46
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
47
47
|
args[_i] = arguments[_i];
|
|
48
48
|
}
|
|
49
|
-
invariant(!calledDuringRender(),
|
|
49
|
+
invariant(!calledDuringRender(), 81);
|
|
50
50
|
var variables = args[0];
|
|
51
51
|
var cacheKey = __spreadArray([
|
|
52
52
|
query,
|
|
@@ -67,7 +67,7 @@ export function useLoadableQuery(query, options) {
|
|
|
67
67
|
client,
|
|
68
68
|
]);
|
|
69
69
|
var subscribeToMore = React.useCallback(function (options) {
|
|
70
|
-
invariant(internalQueryRef,
|
|
70
|
+
invariant(internalQueryRef, 82);
|
|
71
71
|
return internalQueryRef.observable.subscribeToMore(
|
|
72
72
|
// TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here
|
|
73
73
|
options);
|