@apollo/client 3.9.0-alpha.5 → 3.9.0-beta.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/.changeset/chatty-comics-yawn.md +8 -0
- package/.changeset/curvy-seas-hope.md +13 -0
- package/.changeset/dirty-tigers-matter.md +13 -0
- package/.changeset/late-rabbits-protect.md +7 -0
- package/.changeset/mighty-coats-check.md +47 -0
- package/.changeset/pre.json +15 -1
- package/.changeset/rare-snakes-melt.md +24 -0
- package/.changeset/smooth-plums-shout.md +5 -0
- package/.changeset/spicy-drinks-camp.md +5 -0
- package/.changeset/swift-zoos-collect.md +19 -0
- package/.changeset/thick-tips-cry.md +9 -0
- package/.changeset/tough-timers-begin.md +8 -0
- package/.changeset/unlucky-rats-decide.md +5 -0
- package/.changeset/wet-forks-rhyme.md +5 -0
- package/.changeset/wise-news-grab.md +7 -0
- package/CHANGELOG.md +151 -4
- package/apollo-client.cjs +337 -88
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +78 -6
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +78 -6
- package/cache/core/cache.d.ts +9 -0
- package/cache/core/cache.js +11 -2
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +7 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +12 -0
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/core/types/common.d.ts +4 -0
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.js +19 -3
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +9 -0
- package/cache/inmemory/inMemoryCache.js +8 -2
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/readFromStore.js +7 -3
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +18 -0
- package/cache/inmemory/types.js.map +1 -1
- package/core/ApolloClient.d.ts +82 -0
- package/core/ApolloClient.js +4 -0
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +2 -0
- package/core/ObservableQuery.js +15 -5
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +1 -0
- package/core/QueryInfo.js +4 -0
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +1 -1
- package/core/QueryManager.js +15 -10
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +107 -16
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +107 -16
- package/core/watchQueryOptions.d.ts +20 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/link/core/ApolloLink.d.ts +15 -0
- package/link/core/ApolloLink.js +8 -4
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +8 -4
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +8 -4
- package/link/persisted-queries/index.d.ts +11 -1
- package/link/persisted-queries/index.js +28 -3
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +26 -3
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +26 -3
- package/link/remove-typename/remove-typename.cjs +18 -2
- package/link/remove-typename/remove-typename.cjs.map +1 -1
- package/link/remove-typename/remove-typename.cjs.native.js +18 -2
- package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -1
- package/link/remove-typename/removeTypenameFromVariables.js +19 -3
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/retry.cjs +15 -74
- package/link/retry/retry.cjs.map +1 -1
- package/link/retry/retry.cjs.native.js +15 -74
- package/link/retry/retryLink.js +15 -93
- package/link/retry/retryLink.js.map +1 -1
- package/package.json +21 -21
- package/react/components/Mutation.d.ts +6 -0
- package/react/components/Mutation.js +6 -0
- package/react/components/Mutation.js.map +1 -1
- package/react/components/Query.d.ts +6 -0
- package/react/components/Query.js +6 -0
- package/react/components/Query.js.map +1 -1
- package/react/components/Subscription.d.ts +6 -0
- package/react/components/Subscription.js +6 -0
- package/react/components/Subscription.js.map +1 -1
- package/react/components/components.cjs.map +1 -1
- package/react/hoc/graphql.d.ts +5 -0
- package/react/hoc/graphql.js +5 -0
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/mutation-hoc.d.ts +5 -0
- package/react/hoc/mutation-hoc.js +5 -0
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.d.ts +5 -0
- package/react/hoc/query-hoc.js +5 -0
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.d.ts +5 -0
- package/react/hoc/subscription-hoc.js +5 -0
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.d.ts +5 -0
- package/react/hoc/withApollo.js +5 -0
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +48 -257
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +48 -257
- package/react/hooks/index.d.ts +2 -0
- package/react/hooks/index.js +1 -0
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +13 -10
- package/react/hooks/useBackgroundQuery.js +2 -4
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +2 -2
- package/react/hooks/useLoadableQuery.js +2 -4
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +35 -0
- package/react/hooks/useQueryRefHandlers.js +48 -0
- package/react/hooks/useQueryRefHandlers.js.map +1 -0
- package/react/hooks/useReadQuery.d.ts +1 -1
- package/react/hooks/useReadQuery.js +8 -2
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +1 -1
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/index.d.ts +2 -0
- package/react/index.js +1 -0
- package/react/index.js.map +1 -1
- package/react/{cache → internal/cache}/QueryReference.d.ts +13 -7
- package/react/{cache → internal/cache}/QueryReference.js +93 -57
- package/react/internal/cache/QueryReference.js.map +1 -0
- package/react/{cache → internal/cache}/SuspenseCache.d.ts +1 -1
- package/react/{cache → internal/cache}/SuspenseCache.js +1 -1
- package/react/internal/cache/SuspenseCache.js.map +1 -0
- package/react/{cache → internal/cache}/getSuspenseCache.d.ts +3 -3
- package/react/internal/cache/getSuspenseCache.js.map +1 -0
- package/react/internal/cache/types.js.map +1 -0
- package/react/internal/index.d.ts +6 -0
- package/react/internal/index.js +3 -0
- package/react/internal/index.js.map +1 -0
- package/react/internal/internal.cjs +283 -0
- package/react/internal/internal.cjs.map +1 -0
- package/react/internal/internal.cjs.native.js +283 -0
- package/react/internal/package.json +8 -0
- package/react/parser/index.js +6 -3
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +11 -3
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +11 -3
- package/react/query-preloader/createQueryPreloader.d.ts +253 -0
- package/react/query-preloader/createQueryPreloader.js +29 -0
- package/react/query-preloader/createQueryPreloader.js.map +1 -0
- package/react/react.cjs +14 -2
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +14 -2
- package/react/types/types.d.ts +7 -1
- package/react/types/types.js.map +1 -1
- package/testing/internal/ObservableStream.js +16 -8
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/index.d.ts +4 -0
- package/testing/internal/index.js +2 -0
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/renderHelpers.d.ts +12 -0
- package/testing/internal/renderHelpers.js +22 -0
- package/testing/internal/renderHelpers.js.map +1 -0
- package/testing/internal/scenarios/index.d.ts +41 -0
- package/testing/internal/scenarios/index.js +48 -0
- package/testing/internal/scenarios/index.js.map +1 -0
- package/testing/matchers/index.js +2 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toBeDisposed.d.ts +3 -0
- package/testing/matchers/toBeDisposed.js +26 -0
- package/testing/matchers/toBeDisposed.js.map +1 -0
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js +1 -1
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
- package/utilities/caching/caches.d.ts +34 -0
- package/utilities/caching/caches.js +64 -0
- package/utilities/caching/caches.js.map +1 -0
- package/utilities/caching/getMemoryInternals.d.ts +76 -0
- package/utilities/caching/getMemoryInternals.js +112 -0
- package/utilities/caching/getMemoryInternals.js.map +1 -0
- package/utilities/caching/index.d.ts +4 -0
- package/utilities/caching/index.js +3 -0
- package/utilities/caching/index.js.map +1 -0
- package/utilities/caching/sizes.d.ts +311 -0
- package/utilities/caching/sizes.js +27 -0
- package/utilities/caching/sizes.js.map +1 -0
- package/utilities/common/canUse.js +1 -1
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/canonicalStringify.js +8 -2
- package/utilities/common/canonicalStringify.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.d.ts +14 -1
- package/utilities/graphql/DocumentTransform.js +9 -5
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/graphql/print.js +6 -2
- package/utilities/graphql/print.js.map +1 -1
- package/utilities/index.d.ts +2 -0
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/utilities.cjs +57 -9
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +57 -9
- package/version.js +1 -1
- package/react/cache/QueryReference.js.map +0 -1
- package/react/cache/SuspenseCache.js.map +0 -1
- package/react/cache/getSuspenseCache.js.map +0 -1
- package/react/cache/index.d.ts +0 -3
- package/react/cache/index.js +0 -2
- package/react/cache/index.js.map +0 -1
- package/react/cache/types.js.map +0 -1
- /package/react/{cache → internal/cache}/getSuspenseCache.js +0 -0
- /package/react/{cache → internal/cache}/types.d.ts +0 -0
- /package/react/{cache → internal/cache}/types.js +0 -0
|
@@ -11,8 +11,8 @@ var equality = require('@wry/equality');
|
|
|
11
11
|
var errors = require('../../errors');
|
|
12
12
|
var core = require('../../core');
|
|
13
13
|
var parser = require('../parser');
|
|
14
|
+
var internal = require('../internal');
|
|
14
15
|
var cache = require('../../cache');
|
|
15
|
-
var trie = require('@wry/trie');
|
|
16
16
|
|
|
17
17
|
function _interopNamespace(e) {
|
|
18
18
|
if (e && e.__esModule) return e;
|
|
@@ -764,250 +764,12 @@ var __use = realHook ||
|
|
|
764
764
|
}
|
|
765
765
|
};
|
|
766
766
|
|
|
767
|
-
var QUERY_REFERENCE_SYMBOL = Symbol();
|
|
768
|
-
var PROMISE_SYMBOL = Symbol();
|
|
769
|
-
function wrapQueryRef(internalQueryRef) {
|
|
770
|
-
var _a;
|
|
771
|
-
return _a = {},
|
|
772
|
-
_a[QUERY_REFERENCE_SYMBOL] = internalQueryRef,
|
|
773
|
-
_a[PROMISE_SYMBOL] = internalQueryRef.promise,
|
|
774
|
-
_a;
|
|
775
|
-
}
|
|
776
|
-
function unwrapQueryRef(queryRef) {
|
|
777
|
-
var internalQueryRef = queryRef[QUERY_REFERENCE_SYMBOL];
|
|
778
|
-
return [
|
|
779
|
-
internalQueryRef,
|
|
780
|
-
function () {
|
|
781
|
-
return internalQueryRef.promise.status === "fulfilled" ?
|
|
782
|
-
internalQueryRef.promise
|
|
783
|
-
: queryRef[PROMISE_SYMBOL];
|
|
784
|
-
},
|
|
785
|
-
];
|
|
786
|
-
}
|
|
787
|
-
function updateWrappedQueryRef(queryRef, promise) {
|
|
788
|
-
queryRef[PROMISE_SYMBOL] = promise;
|
|
789
|
-
}
|
|
790
|
-
var OBSERVED_CHANGED_OPTIONS = [
|
|
791
|
-
"canonizeResults",
|
|
792
|
-
"context",
|
|
793
|
-
"errorPolicy",
|
|
794
|
-
"fetchPolicy",
|
|
795
|
-
"refetchWritePolicy",
|
|
796
|
-
"returnPartialData",
|
|
797
|
-
];
|
|
798
|
-
var InternalQueryReference = (function () {
|
|
799
|
-
function InternalQueryReference(observable, options) {
|
|
800
|
-
var _this = this;
|
|
801
|
-
this.key = {};
|
|
802
|
-
this.listeners = new Set();
|
|
803
|
-
this.status = "loading";
|
|
804
|
-
this.references = 0;
|
|
805
|
-
this.handleNext = this.handleNext.bind(this);
|
|
806
|
-
this.handleError = this.handleError.bind(this);
|
|
807
|
-
this.dispose = this.dispose.bind(this);
|
|
808
|
-
this.observable = observable;
|
|
809
|
-
this.result = observable.getCurrentResult(false);
|
|
810
|
-
if (options.onDispose) {
|
|
811
|
-
this.onDispose = options.onDispose;
|
|
812
|
-
}
|
|
813
|
-
if (core.isNetworkRequestSettled(this.result.networkStatus) ||
|
|
814
|
-
(this.result.data &&
|
|
815
|
-
(!this.result.partial || this.watchQueryOptions.returnPartialData))) {
|
|
816
|
-
this.promise = utilities.createFulfilledPromise(this.result);
|
|
817
|
-
this.status = "idle";
|
|
818
|
-
}
|
|
819
|
-
else {
|
|
820
|
-
this.promise = utilities.wrapPromiseWithState(new Promise(function (resolve, reject) {
|
|
821
|
-
_this.resolve = resolve;
|
|
822
|
-
_this.reject = reject;
|
|
823
|
-
}));
|
|
824
|
-
}
|
|
825
|
-
this.subscription = observable
|
|
826
|
-
.filter(function (_a) {
|
|
827
|
-
var data = _a.data;
|
|
828
|
-
return !equality.equal(data, {});
|
|
829
|
-
})
|
|
830
|
-
.subscribe({
|
|
831
|
-
next: this.handleNext,
|
|
832
|
-
error: this.handleError,
|
|
833
|
-
});
|
|
834
|
-
var startDisposeTimer = function () {
|
|
835
|
-
var _a;
|
|
836
|
-
if (!_this.references) {
|
|
837
|
-
_this.autoDisposeTimeoutId = setTimeout(_this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
|
|
838
|
-
}
|
|
839
|
-
};
|
|
840
|
-
this.promise.then(startDisposeTimer, startDisposeTimer);
|
|
841
|
-
}
|
|
842
|
-
Object.defineProperty(InternalQueryReference.prototype, "watchQueryOptions", {
|
|
843
|
-
get: function () {
|
|
844
|
-
return this.observable.options;
|
|
845
|
-
},
|
|
846
|
-
enumerable: false,
|
|
847
|
-
configurable: true
|
|
848
|
-
});
|
|
849
|
-
InternalQueryReference.prototype.retain = function () {
|
|
850
|
-
var _this = this;
|
|
851
|
-
this.references++;
|
|
852
|
-
clearTimeout(this.autoDisposeTimeoutId);
|
|
853
|
-
var disposed = false;
|
|
854
|
-
return function () {
|
|
855
|
-
if (disposed) {
|
|
856
|
-
return;
|
|
857
|
-
}
|
|
858
|
-
disposed = true;
|
|
859
|
-
_this.references--;
|
|
860
|
-
setTimeout(function () {
|
|
861
|
-
if (!_this.references) {
|
|
862
|
-
_this.dispose();
|
|
863
|
-
}
|
|
864
|
-
});
|
|
865
|
-
};
|
|
866
|
-
};
|
|
867
|
-
InternalQueryReference.prototype.didChangeOptions = function (watchQueryOptions) {
|
|
868
|
-
var _this = this;
|
|
869
|
-
return OBSERVED_CHANGED_OPTIONS.some(function (option) {
|
|
870
|
-
return !equality.equal(_this.watchQueryOptions[option], watchQueryOptions[option]);
|
|
871
|
-
});
|
|
872
|
-
};
|
|
873
|
-
InternalQueryReference.prototype.applyOptions = function (watchQueryOptions) {
|
|
874
|
-
var _a = this.watchQueryOptions, currentFetchPolicy = _a.fetchPolicy, currentCanonizeResults = _a.canonizeResults;
|
|
875
|
-
if (currentFetchPolicy === "standby" &&
|
|
876
|
-
currentFetchPolicy !== watchQueryOptions.fetchPolicy) {
|
|
877
|
-
this.initiateFetch(this.observable.reobserve(watchQueryOptions));
|
|
878
|
-
}
|
|
879
|
-
else {
|
|
880
|
-
this.observable.silentSetOptions(watchQueryOptions);
|
|
881
|
-
if (currentCanonizeResults !== watchQueryOptions.canonizeResults) {
|
|
882
|
-
this.result = tslib.__assign(tslib.__assign({}, this.result), this.observable.getCurrentResult());
|
|
883
|
-
this.promise = utilities.createFulfilledPromise(this.result);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
return this.promise;
|
|
887
|
-
};
|
|
888
|
-
InternalQueryReference.prototype.listen = function (listener) {
|
|
889
|
-
var _this = this;
|
|
890
|
-
this.listeners.add(listener);
|
|
891
|
-
return function () {
|
|
892
|
-
_this.listeners.delete(listener);
|
|
893
|
-
};
|
|
894
|
-
};
|
|
895
|
-
InternalQueryReference.prototype.refetch = function (variables) {
|
|
896
|
-
return this.initiateFetch(this.observable.refetch(variables));
|
|
897
|
-
};
|
|
898
|
-
InternalQueryReference.prototype.fetchMore = function (options) {
|
|
899
|
-
return this.initiateFetch(this.observable.fetchMore(options));
|
|
900
|
-
};
|
|
901
|
-
InternalQueryReference.prototype.dispose = function () {
|
|
902
|
-
this.subscription.unsubscribe();
|
|
903
|
-
this.onDispose();
|
|
904
|
-
};
|
|
905
|
-
InternalQueryReference.prototype.onDispose = function () {
|
|
906
|
-
};
|
|
907
|
-
InternalQueryReference.prototype.handleNext = function (result) {
|
|
908
|
-
var _a;
|
|
909
|
-
switch (this.status) {
|
|
910
|
-
case "loading": {
|
|
911
|
-
if (result.data === void 0) {
|
|
912
|
-
result.data = this.result.data;
|
|
913
|
-
}
|
|
914
|
-
this.status = "idle";
|
|
915
|
-
this.result = result;
|
|
916
|
-
(_a = this.resolve) === null || _a === void 0 ? void 0 : _a.call(this, result);
|
|
917
|
-
break;
|
|
918
|
-
}
|
|
919
|
-
case "idle": {
|
|
920
|
-
if (result.data === this.result.data) {
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
if (result.data === void 0) {
|
|
924
|
-
result.data = this.result.data;
|
|
925
|
-
}
|
|
926
|
-
this.result = result;
|
|
927
|
-
this.promise = utilities.createFulfilledPromise(result);
|
|
928
|
-
this.deliver(this.promise);
|
|
929
|
-
break;
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
InternalQueryReference.prototype.handleError = function (error) {
|
|
934
|
-
var _a;
|
|
935
|
-
this.subscription.unsubscribe();
|
|
936
|
-
this.subscription = this.observable.resubscribeAfterError(this.handleNext, this.handleError);
|
|
937
|
-
switch (this.status) {
|
|
938
|
-
case "loading": {
|
|
939
|
-
this.status = "idle";
|
|
940
|
-
(_a = this.reject) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
941
|
-
break;
|
|
942
|
-
}
|
|
943
|
-
case "idle": {
|
|
944
|
-
this.promise = utilities.createRejectedPromise(error);
|
|
945
|
-
this.deliver(this.promise);
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
};
|
|
949
|
-
InternalQueryReference.prototype.deliver = function (promise) {
|
|
950
|
-
this.listeners.forEach(function (listener) { return listener(promise); });
|
|
951
|
-
};
|
|
952
|
-
InternalQueryReference.prototype.initiateFetch = function (returnedPromise) {
|
|
953
|
-
var _this = this;
|
|
954
|
-
this.status = "loading";
|
|
955
|
-
this.promise = utilities.wrapPromiseWithState(new Promise(function (resolve, reject) {
|
|
956
|
-
_this.resolve = resolve;
|
|
957
|
-
_this.reject = reject;
|
|
958
|
-
}));
|
|
959
|
-
this.promise.catch(function () { });
|
|
960
|
-
returnedPromise
|
|
961
|
-
.then(function (result) {
|
|
962
|
-
var _a;
|
|
963
|
-
if (_this.status === "loading") {
|
|
964
|
-
_this.status = "idle";
|
|
965
|
-
_this.result = result;
|
|
966
|
-
(_a = _this.resolve) === null || _a === void 0 ? void 0 : _a.call(_this, result);
|
|
967
|
-
}
|
|
968
|
-
})
|
|
969
|
-
.catch(function () { });
|
|
970
|
-
return returnedPromise;
|
|
971
|
-
};
|
|
972
|
-
return InternalQueryReference;
|
|
973
|
-
}());
|
|
974
|
-
|
|
975
|
-
var SuspenseCache = (function () {
|
|
976
|
-
function SuspenseCache(options) {
|
|
977
|
-
if (options === void 0) { options = Object.create(null); }
|
|
978
|
-
this.queryRefs = new trie.Trie(utilities.canUseWeakMap);
|
|
979
|
-
this.options = options;
|
|
980
|
-
}
|
|
981
|
-
SuspenseCache.prototype.getQueryRef = function (cacheKey, createObservable) {
|
|
982
|
-
var ref = this.queryRefs.lookupArray(cacheKey);
|
|
983
|
-
if (!ref.current) {
|
|
984
|
-
ref.current = new InternalQueryReference(createObservable(), {
|
|
985
|
-
autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,
|
|
986
|
-
onDispose: function () {
|
|
987
|
-
delete ref.current;
|
|
988
|
-
},
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
return ref.current;
|
|
992
|
-
};
|
|
993
|
-
return SuspenseCache;
|
|
994
|
-
}());
|
|
995
|
-
|
|
996
|
-
var suspenseCacheSymbol = Symbol.for("apollo.suspenseCache");
|
|
997
|
-
function getSuspenseCache(client) {
|
|
998
|
-
var _a;
|
|
999
|
-
if (!client[suspenseCacheSymbol]) {
|
|
1000
|
-
client[suspenseCacheSymbol] = new SuspenseCache((_a = client.defaultOptions.react) === null || _a === void 0 ? void 0 : _a.suspense);
|
|
1001
|
-
}
|
|
1002
|
-
return client[suspenseCacheSymbol];
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
767
|
var skipToken = Symbol.for("apollo.skipToken");
|
|
1006
768
|
|
|
1007
769
|
function useSuspenseQuery(query, options) {
|
|
1008
770
|
if (options === void 0) { options = Object.create(null); }
|
|
1009
771
|
var client = useApolloClient(options.client);
|
|
1010
|
-
var suspenseCache = getSuspenseCache(client);
|
|
772
|
+
var suspenseCache = internal.getSuspenseCache(client);
|
|
1011
773
|
var watchQueryOptions = useWatchQueryOptions({
|
|
1012
774
|
client: client,
|
|
1013
775
|
query: query,
|
|
@@ -1124,7 +886,7 @@ function useWatchQueryOptions(_a) {
|
|
|
1124
886
|
function useBackgroundQuery(query, options) {
|
|
1125
887
|
if (options === void 0) { options = Object.create(null); }
|
|
1126
888
|
var client = useApolloClient(options.client);
|
|
1127
|
-
var suspenseCache = getSuspenseCache(client);
|
|
889
|
+
var suspenseCache = internal.getSuspenseCache(client);
|
|
1128
890
|
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
1129
891
|
var fetchPolicy = watchQueryOptions.fetchPolicy, variables = watchQueryOptions.variables;
|
|
1130
892
|
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
|
|
@@ -1137,23 +899,22 @@ function useBackgroundQuery(query, options) {
|
|
|
1137
899
|
var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
|
|
1138
900
|
return client.watchQuery(watchQueryOptions);
|
|
1139
901
|
});
|
|
1140
|
-
var _b = React__namespace.useState(wrapQueryRef(queryRef)), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];
|
|
1141
|
-
if (unwrapQueryRef(wrappedQueryRef)
|
|
1142
|
-
setWrappedQueryRef(wrapQueryRef(queryRef));
|
|
902
|
+
var _b = React__namespace.useState(internal.wrapQueryRef(queryRef)), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];
|
|
903
|
+
if (internal.unwrapQueryRef(wrappedQueryRef) !== queryRef) {
|
|
904
|
+
setWrappedQueryRef(internal.wrapQueryRef(queryRef));
|
|
1143
905
|
}
|
|
1144
906
|
if (queryRef.didChangeOptions(watchQueryOptions)) {
|
|
1145
907
|
var promise = queryRef.applyOptions(watchQueryOptions);
|
|
1146
|
-
updateWrappedQueryRef(wrappedQueryRef, promise);
|
|
908
|
+
internal.updateWrappedQueryRef(wrappedQueryRef, promise);
|
|
1147
909
|
}
|
|
1148
|
-
React__namespace.useEffect(function () { return queryRef.retain(); }, [queryRef]);
|
|
1149
910
|
var fetchMore = React__namespace.useCallback(function (options) {
|
|
1150
911
|
var promise = queryRef.fetchMore(options);
|
|
1151
|
-
setWrappedQueryRef(wrapQueryRef(queryRef));
|
|
912
|
+
setWrappedQueryRef(internal.wrapQueryRef(queryRef));
|
|
1152
913
|
return promise;
|
|
1153
914
|
}, [queryRef]);
|
|
1154
915
|
var refetch = React__namespace.useCallback(function (variables) {
|
|
1155
916
|
var promise = queryRef.refetch(variables);
|
|
1156
|
-
setWrappedQueryRef(wrapQueryRef(queryRef));
|
|
917
|
+
setWrappedQueryRef(internal.wrapQueryRef(queryRef));
|
|
1157
918
|
return promise;
|
|
1158
919
|
}, [queryRef]);
|
|
1159
920
|
return [
|
|
@@ -1165,23 +926,22 @@ function useBackgroundQuery(query, options) {
|
|
|
1165
926
|
function useLoadableQuery(query, options) {
|
|
1166
927
|
if (options === void 0) { options = Object.create(null); }
|
|
1167
928
|
var client = useApolloClient(options.client);
|
|
1168
|
-
var suspenseCache = getSuspenseCache(client);
|
|
929
|
+
var suspenseCache = internal.getSuspenseCache(client);
|
|
1169
930
|
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
1170
931
|
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
|
|
1171
932
|
var _b = React__namespace.useState(null), queryRef = _b[0], setQueryRef = _b[1];
|
|
1172
|
-
var internalQueryRef = queryRef && unwrapQueryRef(queryRef)
|
|
933
|
+
var internalQueryRef = queryRef && internal.unwrapQueryRef(queryRef);
|
|
1173
934
|
if (queryRef && (internalQueryRef === null || internalQueryRef === void 0 ? void 0 : internalQueryRef.didChangeOptions(watchQueryOptions))) {
|
|
1174
935
|
var promise = internalQueryRef.applyOptions(watchQueryOptions);
|
|
1175
|
-
updateWrappedQueryRef(queryRef, promise);
|
|
936
|
+
internal.updateWrappedQueryRef(queryRef, promise);
|
|
1176
937
|
}
|
|
1177
938
|
var calledDuringRender = useRenderGuard();
|
|
1178
|
-
React__namespace.useEffect(function () { return internalQueryRef === null || internalQueryRef === void 0 ? void 0 : internalQueryRef.retain(); }, [internalQueryRef]);
|
|
1179
939
|
var fetchMore = React__namespace.useCallback(function (options) {
|
|
1180
940
|
if (!internalQueryRef) {
|
|
1181
941
|
throw new Error("The query has not been loaded. Please load the query.");
|
|
1182
942
|
}
|
|
1183
943
|
var promise = internalQueryRef.fetchMore(options);
|
|
1184
|
-
setQueryRef(wrapQueryRef(internalQueryRef));
|
|
944
|
+
setQueryRef(internal.wrapQueryRef(internalQueryRef));
|
|
1185
945
|
return promise;
|
|
1186
946
|
}, [internalQueryRef]);
|
|
1187
947
|
var refetch = React__namespace.useCallback(function (options) {
|
|
@@ -1189,7 +949,7 @@ function useLoadableQuery(query, options) {
|
|
|
1189
949
|
throw new Error("The query has not been loaded. Please load the query.");
|
|
1190
950
|
}
|
|
1191
951
|
var promise = internalQueryRef.refetch(options);
|
|
1192
|
-
setQueryRef(wrapQueryRef(internalQueryRef));
|
|
952
|
+
setQueryRef(internal.wrapQueryRef(internalQueryRef));
|
|
1193
953
|
return promise;
|
|
1194
954
|
}, [internalQueryRef]);
|
|
1195
955
|
var loadQuery = React__namespace.useCallback(function () {
|
|
@@ -1206,7 +966,7 @@ function useLoadableQuery(query, options) {
|
|
|
1206
966
|
var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
|
|
1207
967
|
return client.watchQuery(tslib.__assign(tslib.__assign({}, watchQueryOptions), { variables: variables }));
|
|
1208
968
|
});
|
|
1209
|
-
setQueryRef(wrapQueryRef(queryRef));
|
|
969
|
+
setQueryRef(internal.wrapQueryRef(queryRef));
|
|
1210
970
|
}, [query, queryKey, suspenseCache, watchQueryOptions, calledDuringRender]);
|
|
1211
971
|
var reset = React__namespace.useCallback(function () {
|
|
1212
972
|
setQueryRef(null);
|
|
@@ -1214,11 +974,41 @@ function useLoadableQuery(query, options) {
|
|
|
1214
974
|
return [loadQuery, queryRef, { fetchMore: fetchMore, refetch: refetch, reset: reset }];
|
|
1215
975
|
}
|
|
1216
976
|
|
|
977
|
+
function useQueryRefHandlers(queryRef) {
|
|
978
|
+
var _a = React__namespace.useState(queryRef), previousQueryRef = _a[0], setPreviousQueryRef = _a[1];
|
|
979
|
+
var _b = React__namespace.useState(queryRef), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];
|
|
980
|
+
var internalQueryRef = internal.unwrapQueryRef(queryRef);
|
|
981
|
+
if (previousQueryRef !== queryRef) {
|
|
982
|
+
setPreviousQueryRef(queryRef);
|
|
983
|
+
setWrappedQueryRef(queryRef);
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
internal.updateWrappedQueryRef(queryRef, internal.getWrappedPromise(wrappedQueryRef));
|
|
987
|
+
}
|
|
988
|
+
var refetch = React__namespace.useCallback(function (variables) {
|
|
989
|
+
var promise = internalQueryRef.refetch(variables);
|
|
990
|
+
setWrappedQueryRef(internal.wrapQueryRef(internalQueryRef));
|
|
991
|
+
return promise;
|
|
992
|
+
}, [internalQueryRef]);
|
|
993
|
+
var fetchMore = React__namespace.useCallback(function (options) {
|
|
994
|
+
var promise = internalQueryRef.fetchMore(options);
|
|
995
|
+
setWrappedQueryRef(internal.wrapQueryRef(internalQueryRef));
|
|
996
|
+
return promise;
|
|
997
|
+
}, [internalQueryRef]);
|
|
998
|
+
return { refetch: refetch, fetchMore: fetchMore };
|
|
999
|
+
}
|
|
1000
|
+
|
|
1217
1001
|
function useReadQuery(queryRef) {
|
|
1218
|
-
var
|
|
1002
|
+
var internalQueryRef = React__namespace.useMemo(function () { return internal.unwrapQueryRef(queryRef); }, [queryRef]);
|
|
1003
|
+
var getPromise = React__namespace.useCallback(function () { return internal.getWrappedPromise(queryRef); }, [queryRef]);
|
|
1004
|
+
if (internalQueryRef.disposed) {
|
|
1005
|
+
internalQueryRef.reinitialize();
|
|
1006
|
+
internal.updateWrappedQueryRef(queryRef, internalQueryRef.promise);
|
|
1007
|
+
}
|
|
1008
|
+
React__namespace.useEffect(function () { return internalQueryRef.retain(); }, [internalQueryRef]);
|
|
1219
1009
|
var promise = useSyncExternalStore(React__namespace.useCallback(function (forceUpdate) {
|
|
1220
1010
|
return internalQueryRef.listen(function (promise) {
|
|
1221
|
-
updateWrappedQueryRef(queryRef, promise);
|
|
1011
|
+
internal.updateWrappedQueryRef(queryRef, promise);
|
|
1222
1012
|
forceUpdate();
|
|
1223
1013
|
});
|
|
1224
1014
|
}, [internalQueryRef]), getPromise, getPromise);
|
|
@@ -1240,6 +1030,7 @@ exports.useLazyQuery = useLazyQuery;
|
|
|
1240
1030
|
exports.useLoadableQuery = useLoadableQuery;
|
|
1241
1031
|
exports.useMutation = useMutation;
|
|
1242
1032
|
exports.useQuery = useQuery;
|
|
1033
|
+
exports.useQueryRefHandlers = useQueryRefHandlers;
|
|
1243
1034
|
exports.useReactiveVar = useReactiveVar;
|
|
1244
1035
|
exports.useReadQuery = useReadQuery;
|
|
1245
1036
|
exports.useSubscription = useSubscription;
|
package/react/hooks/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export type { UseBackgroundQueryResult } from "./useBackgroundQuery.js";
|
|
|
12
12
|
export { useBackgroundQuery } from "./useBackgroundQuery.js";
|
|
13
13
|
export type { LoadQueryFunction, UseLoadableQueryResult, } from "./useLoadableQuery.js";
|
|
14
14
|
export { useLoadableQuery } from "./useLoadableQuery.js";
|
|
15
|
+
export type { UseQueryRefHandlersResult } from "./useQueryRefHandlers.js";
|
|
16
|
+
export { useQueryRefHandlers } from "./useQueryRefHandlers.js";
|
|
15
17
|
export type { UseReadQueryResult } from "./useReadQuery.js";
|
|
16
18
|
export { useReadQuery } from "./useReadQuery.js";
|
|
17
19
|
export { skipToken } from "./constants.js";
|
package/react/hooks/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./useFragment.js";
|
|
|
9
9
|
export { useSuspenseQuery } from "./useSuspenseQuery.js";
|
|
10
10
|
export { useBackgroundQuery } from "./useBackgroundQuery.js";
|
|
11
11
|
export { useLoadableQuery } from "./useLoadableQuery.js";
|
|
12
|
+
export { useQueryRefHandlers } from "./useQueryRefHandlers.js";
|
|
12
13
|
export { useReadQuery } from "./useReadQuery.js";
|
|
13
14
|
export { skipToken } from "./constants.js";
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/react/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAK7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["import \"../../utilities/globals/index.js\";\n\nexport * from \"./useApolloClient.js\";\nexport * from \"./useLazyQuery.js\";\nexport * from \"./useMutation.js\";\nexport { useQuery } from \"./useQuery.js\";\nexport * from \"./useSubscription.js\";\nexport * from \"./useReactiveVar.js\";\nexport * from \"./useFragment.js\";\nexport type { UseSuspenseQueryResult } from \"./useSuspenseQuery.js\";\nexport { useSuspenseQuery } from \"./useSuspenseQuery.js\";\nexport type { UseBackgroundQueryResult } from \"./useBackgroundQuery.js\";\nexport { useBackgroundQuery } from \"./useBackgroundQuery.js\";\nexport type {\n LoadQueryFunction,\n UseLoadableQueryResult,\n} from \"./useLoadableQuery.js\";\nexport { useLoadableQuery } from \"./useLoadableQuery.js\";\nexport type { UseReadQueryResult } from \"./useReadQuery.js\";\nexport { useReadQuery } from \"./useReadQuery.js\";\nexport { skipToken } from \"./constants.js\";\nexport type { SkipToken } from \"./constants.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC;AAE1C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAK7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["import \"../../utilities/globals/index.js\";\n\nexport * from \"./useApolloClient.js\";\nexport * from \"./useLazyQuery.js\";\nexport * from \"./useMutation.js\";\nexport { useQuery } from \"./useQuery.js\";\nexport * from \"./useSubscription.js\";\nexport * from \"./useReactiveVar.js\";\nexport * from \"./useFragment.js\";\nexport type { UseSuspenseQueryResult } from \"./useSuspenseQuery.js\";\nexport { useSuspenseQuery } from \"./useSuspenseQuery.js\";\nexport type { UseBackgroundQueryResult } from \"./useBackgroundQuery.js\";\nexport { useBackgroundQuery } from \"./useBackgroundQuery.js\";\nexport type {\n LoadQueryFunction,\n UseLoadableQueryResult,\n} from \"./useLoadableQuery.js\";\nexport { useLoadableQuery } from \"./useLoadableQuery.js\";\nexport type { UseQueryRefHandlersResult } from \"./useQueryRefHandlers.js\";\nexport { useQueryRefHandlers } from \"./useQueryRefHandlers.js\";\nexport type { UseReadQueryResult } from \"./useReadQuery.js\";\nexport { useReadQuery } from \"./useReadQuery.js\";\nexport { skipToken } from \"./constants.js\";\nexport type { SkipToken } from \"./constants.js\";\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocumentNode, OperationVariables, TypedDocumentNode } from "../../core/index.js";
|
|
2
|
-
import type { QueryReference } from "../
|
|
2
|
+
import type { QueryReference } from "../internal/index.js";
|
|
3
3
|
import type { BackgroundQueryHookOptions, NoInfer } from "../types/types.js";
|
|
4
4
|
import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js";
|
|
5
5
|
import type { DeepPartial } from "../../utilities/index.js";
|
|
@@ -10,51 +10,54 @@ export type UseBackgroundQueryResult<TData = unknown, TVariables extends Operati
|
|
|
10
10
|
};
|
|
11
11
|
type BackgroundQueryHookOptionsNoInfer<TData, TVariables extends OperationVariables> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;
|
|
12
12
|
export declare function useBackgroundQuery<TData, TVariables extends OperationVariables, TOptions extends Omit<BackgroundQueryHookOptions<TData>, "variables">>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions): [
|
|
13
|
-
(QueryReference<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData> | (TOptions["skip"] extends boolean ? undefined : never)),
|
|
13
|
+
(QueryReference<TOptions["errorPolicy"] extends "ignore" | "all" ? TOptions["returnPartialData"] extends true ? DeepPartial<TData> | undefined : TData | undefined : TOptions["returnPartialData"] extends true ? DeepPartial<TData> : TData, TVariables> | (TOptions["skip"] extends boolean ? undefined : never)),
|
|
14
14
|
UseBackgroundQueryResult<TData, TVariables>
|
|
15
15
|
];
|
|
16
16
|
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
|
|
17
17
|
returnPartialData: true;
|
|
18
18
|
errorPolicy: "ignore" | "all";
|
|
19
19
|
}): [
|
|
20
|
-
QueryReference<DeepPartial<TData> | undefined>,
|
|
20
|
+
QueryReference<DeepPartial<TData> | undefined, TVariables>,
|
|
21
21
|
UseBackgroundQueryResult<TData, TVariables>
|
|
22
22
|
];
|
|
23
23
|
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
|
|
24
24
|
errorPolicy: "ignore" | "all";
|
|
25
25
|
}): [
|
|
26
|
-
QueryReference<TData | undefined>,
|
|
26
|
+
QueryReference<TData | undefined, TVariables>,
|
|
27
27
|
UseBackgroundQueryResult<TData, TVariables>
|
|
28
28
|
];
|
|
29
29
|
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
|
|
30
30
|
skip: boolean;
|
|
31
31
|
returnPartialData: true;
|
|
32
32
|
}): [
|
|
33
|
-
QueryReference<DeepPartial<TData
|
|
33
|
+
QueryReference<DeepPartial<TData>, TVariables> | undefined,
|
|
34
34
|
UseBackgroundQueryResult<TData, TVariables>
|
|
35
35
|
];
|
|
36
36
|
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
|
|
37
37
|
returnPartialData: true;
|
|
38
38
|
}): [
|
|
39
|
-
QueryReference<DeepPartial<TData
|
|
39
|
+
QueryReference<DeepPartial<TData>, TVariables>,
|
|
40
40
|
UseBackgroundQueryResult<TData, TVariables>
|
|
41
41
|
];
|
|
42
42
|
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
|
|
43
43
|
skip: boolean;
|
|
44
44
|
}): [
|
|
45
|
-
QueryReference<TData> | undefined,
|
|
45
|
+
QueryReference<TData, TVariables> | undefined,
|
|
46
|
+
UseBackgroundQueryResult<TData, TVariables>
|
|
47
|
+
];
|
|
48
|
+
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [
|
|
49
|
+
QueryReference<TData, TVariables>,
|
|
46
50
|
UseBackgroundQueryResult<TData, TVariables>
|
|
47
51
|
];
|
|
48
|
-
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [QueryReference<TData>, UseBackgroundQueryResult<TData, TVariables>];
|
|
49
52
|
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): [undefined, UseBackgroundQueryResult<TData, TVariables>];
|
|
50
53
|
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {
|
|
51
54
|
returnPartialData: true;
|
|
52
55
|
})): [
|
|
53
|
-
QueryReference<DeepPartial<TData
|
|
56
|
+
QueryReference<DeepPartial<TData>, TVariables> | undefined,
|
|
54
57
|
UseBackgroundQueryResult<TData, TVariables>
|
|
55
58
|
];
|
|
56
59
|
export declare function useBackgroundQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>): [
|
|
57
|
-
QueryReference<TData> | undefined,
|
|
60
|
+
QueryReference<TData, TVariables> | undefined,
|
|
58
61
|
UseBackgroundQueryResult<TData, TVariables>
|
|
59
62
|
];
|
|
60
63
|
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { __spreadArray } from "tslib";
|
|
2
2
|
import * as React from "rehackt";
|
|
3
3
|
import { useApolloClient } from "./useApolloClient.js";
|
|
4
|
-
import { unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../
|
|
5
|
-
import { getSuspenseCache } from "../cache/index.js";
|
|
4
|
+
import { getSuspenseCache, unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../internal/index.js";
|
|
6
5
|
import { useWatchQueryOptions } from "./useSuspenseQuery.js";
|
|
7
6
|
import { canonicalStringify } from "../../cache/index.js";
|
|
8
7
|
export function useBackgroundQuery(query, options) {
|
|
@@ -28,14 +27,13 @@ export function useBackgroundQuery(query, options) {
|
|
|
28
27
|
return client.watchQuery(watchQueryOptions);
|
|
29
28
|
});
|
|
30
29
|
var _b = React.useState(wrapQueryRef(queryRef)), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];
|
|
31
|
-
if (unwrapQueryRef(wrappedQueryRef)
|
|
30
|
+
if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {
|
|
32
31
|
setWrappedQueryRef(wrapQueryRef(queryRef));
|
|
33
32
|
}
|
|
34
33
|
if (queryRef.didChangeOptions(watchQueryOptions)) {
|
|
35
34
|
var promise = queryRef.applyOptions(watchQueryOptions);
|
|
36
35
|
updateWrappedQueryRef(wrappedQueryRef, promise);
|
|
37
36
|
}
|
|
38
|
-
React.useEffect(function () { return queryRef.retain(); }, [queryRef]);
|
|
39
37
|
var fetchMore = React.useCallback(function (options) {
|
|
40
38
|
var promise = queryRef.fetchMore(options);
|
|
41
39
|
setWrappedQueryRef(wrapQueryRef(queryRef));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from \"rehackt\";\nimport type {\n DocumentNode,\n FetchMoreQueryOptions,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../cache/QueryReference.js\";\nimport type { QueryReference } from \"../cache/QueryReference.js\";\nimport type { BackgroundQueryHookOptions, NoInfer } from \"../types/types.js\";\nimport { __use } from \"./internal/index.js\";\nimport { getSuspenseCache } from \"../cache/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 { CacheKey } from \"../cache/types.js\";\nimport type { SkipToken } from \"./constants.js\";\n\nexport type UseBackgroundQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = {\n fetchMore: FetchMoreFunction<TData, TVariables>;\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 | QueryReference<\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 >\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 QueryReference<DeepPartial<TData> | 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 errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryReference<TData | 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 skip: boolean;\n returnPartialData: true;\n }\n): [\n QueryReference<DeepPartial<TData>> | 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 QueryReference<DeepPartial<TData>>,\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 QueryReference<TData> | 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): [QueryReference<TData>, 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 QueryReference<DeepPartial<TData>> | 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 QueryReference<TData> | 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 QueryReference<TData> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\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 = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions as WatchQueryOptions<any, any>)\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef)[0] !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n React.useEffect(() => queryRef.retain(), [queryRef]);\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 return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n { fetchMore, refetch },\n ];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from \"rehackt\";\nimport type {\n DocumentNode,\n FetchMoreQueryOptions,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../internal/index.js\";\nimport type { CacheKey, QueryReference } from \"../internal/index.js\";\nimport type { BackgroundQueryHookOptions, NoInfer } from \"../types/types.js\";\nimport { __use } 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\";\n\nexport type UseBackgroundQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = {\n fetchMore: FetchMoreFunction<TData, TVariables>;\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 | QueryReference<\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 QueryReference<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 QueryReference<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 QueryReference<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 QueryReference<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 QueryReference<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): [\n QueryReference<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: 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 QueryReference<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 QueryReference<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 QueryReference<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\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 = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions as WatchQueryOptions<any, any>)\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 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 return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n { fetchMore, refetch },\n ];\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocumentNode, OperationVariables, TypedDocumentNode } from "../../core/index.js";
|
|
2
|
-
import type { QueryReference } from "../
|
|
2
|
+
import type { QueryReference } from "../internal/index.js";
|
|
3
3
|
import type { LoadableQueryHookOptions } from "../types/types.js";
|
|
4
4
|
import type { FetchMoreFunction, RefetchFunction } from "./useSuspenseQuery.js";
|
|
5
5
|
import type { DeepPartial, OnlyRequiredProperties } from "../../utilities/index.js";
|
|
@@ -7,7 +7,7 @@ export type LoadQueryFunction<TVariables extends OperationVariables> = (...args:
|
|
|
7
7
|
type ResetFunction = () => void;
|
|
8
8
|
export type UseLoadableQueryResult<TData = unknown, TVariables extends OperationVariables = OperationVariables> = [
|
|
9
9
|
LoadQueryFunction<TVariables>,
|
|
10
|
-
QueryReference<TData> | null,
|
|
10
|
+
QueryReference<TData, TVariables> | null,
|
|
11
11
|
{
|
|
12
12
|
fetchMore: FetchMoreFunction<TData, TVariables>;
|
|
13
13
|
refetch: RefetchFunction<TData, TVariables>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { __assign, __spreadArray } from "tslib";
|
|
2
2
|
import * as React from "rehackt";
|
|
3
3
|
import { useApolloClient } from "./useApolloClient.js";
|
|
4
|
-
import { unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../
|
|
4
|
+
import { getSuspenseCache, unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef, } from "../internal/index.js";
|
|
5
5
|
import { useRenderGuard } from "./internal/index.js";
|
|
6
|
-
import { getSuspenseCache } from "../cache/index.js";
|
|
7
6
|
import { useWatchQueryOptions } from "./useSuspenseQuery.js";
|
|
8
7
|
import { canonicalStringify } from "../../cache/index.js";
|
|
9
8
|
import { invariant } from "../../utilities/globals/index.js";
|
|
@@ -14,13 +13,12 @@ export function useLoadableQuery(query, options) {
|
|
|
14
13
|
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
15
14
|
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
|
|
16
15
|
var _b = React.useState(null), queryRef = _b[0], setQueryRef = _b[1];
|
|
17
|
-
var internalQueryRef = queryRef && unwrapQueryRef(queryRef)
|
|
16
|
+
var internalQueryRef = queryRef && unwrapQueryRef(queryRef);
|
|
18
17
|
if (queryRef && (internalQueryRef === null || internalQueryRef === void 0 ? void 0 : internalQueryRef.didChangeOptions(watchQueryOptions))) {
|
|
19
18
|
var promise = internalQueryRef.applyOptions(watchQueryOptions);
|
|
20
19
|
updateWrappedQueryRef(queryRef, promise);
|
|
21
20
|
}
|
|
22
21
|
var calledDuringRender = useRenderGuard();
|
|
23
|
-
React.useEffect(function () { return internalQueryRef === null || internalQueryRef === void 0 ? void 0 : internalQueryRef.retain(); }, [internalQueryRef]);
|
|
24
22
|
var fetchMore = React.useCallback(function (options) {
|
|
25
23
|
if (!internalQueryRef) {
|
|
26
24
|
throw new Error("The query has not been loaded. Please load the query.");
|