@apollo/client 4.0.0-alpha.3 → 4.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/eighty-squids-fix.md +15 -0
- package/.changeset/funny-jeans-invent.md +16 -0
- package/.changeset/khaki-spies-work.md +11 -0
- package/.changeset/light-apes-rescue.md +5 -0
- package/.changeset/odd-lemons-relax.md +5 -0
- package/.changeset/pre.json +5 -0
- package/CHANGELOG.md +44 -0
- package/__cjs/core/ApolloClient.cjs +22 -13
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +13 -1
- package/__cjs/core/ObservableQuery.cjs +29 -10
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +6 -3
- package/__cjs/core/QueryManager.cjs +15 -0
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +11 -0
- package/__cjs/core/watchQueryOptions.d.cts +18 -25
- package/__cjs/react/hooks/index.cjs +13 -8
- package/__cjs/react/hooks/index.cjs.map +1 -1
- package/__cjs/react/hooks/index.d.cts +6 -12
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +146 -43
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +51 -26
- package/__cjs/react/hooks/useLazyQuery.cjs +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +263 -262
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +105 -32
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +198 -3
- package/__cjs/react/hooks/useQuery.cjs +9 -11
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +279 -4
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +21 -20
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +26 -24
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +127 -4
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.d.cts +40 -37
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +202 -35
- package/__cjs/react/index.cjs.map +1 -1
- package/__cjs/react/index.d.cts +2 -1
- package/__cjs/react/internal/index.cjs.map +1 -1
- package/__cjs/react/internal/index.d.cts +1 -0
- package/__cjs/react/internal/types.d.cts +46 -0
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +2 -3
- package/__cjs/react/ssr/RenderPromises.cjs.map +1 -1
- package/__cjs/react/ssr/RenderPromises.d.cts +6 -3
- package/__cjs/react/types/deprecated.cjs +3 -0
- package/__cjs/react/types/deprecated.cjs.map +1 -0
- package/__cjs/react/types/deprecated.d.cts +65 -0
- package/__cjs/testing/matchers/index.cjs +2 -0
- package/__cjs/testing/matchers/index.cjs.map +1 -1
- package/__cjs/testing/matchers/toEqualLazyQueryResult.cjs.map +1 -1
- package/__cjs/testing/matchers/toEqualLazyQueryResult.d.cts +2 -2
- package/__cjs/testing/matchers/toEqualQueryResult.cjs.map +1 -1
- package/__cjs/testing/matchers/toEqualQueryResult.d.cts +2 -2
- package/__cjs/testing/matchers/toEqualStrictTyped.cjs +44 -0
- package/__cjs/testing/matchers/toEqualStrictTyped.cjs.map +1 -0
- package/__cjs/testing/matchers/toEqualStrictTyped.d.cts +3 -0
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.d.cts +1 -1
- package/core/ApolloClient.d.ts +13 -1
- package/core/ApolloClient.js +22 -13
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +6 -3
- package/core/ObservableQuery.js +29 -10
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.d.ts +11 -0
- package/core/QueryManager.js +15 -0
- package/core/QueryManager.js.map +1 -1
- package/core/watchQueryOptions.d.ts +18 -25
- package/package.json +1 -1
- package/react/hooks/index.d.ts +6 -12
- package/react/hooks/index.js +6 -6
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +146 -43
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.d.ts +51 -26
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +263 -262
- package/react/hooks/useLazyQuery.js +1 -1
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +105 -32
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +198 -3
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +279 -4
- package/react/hooks/useQuery.js +9 -11
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +21 -20
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +26 -24
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +127 -4
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.d.ts +40 -37
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +202 -35
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/index.d.ts +2 -1
- package/react/index.js.map +1 -1
- package/react/internal/index.d.ts +1 -0
- package/react/internal/index.js.map +1 -1
- package/react/internal/types.d.ts +46 -0
- package/react/query-preloader/createQueryPreloader.d.ts +2 -3
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/ssr/RenderPromises.d.ts +6 -3
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/types/deprecated.d.ts +65 -0
- package/react/types/deprecated.js +2 -0
- package/react/types/deprecated.js.map +1 -0
- package/testing/matchers/index.js +2 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toEqualLazyQueryResult.d.ts +2 -2
- package/testing/matchers/toEqualLazyQueryResult.js.map +1 -1
- package/testing/matchers/toEqualQueryResult.d.ts +2 -2
- package/testing/matchers/toEqualQueryResult.js.map +1 -1
- package/testing/matchers/toEqualStrictTyped.d.ts +3 -0
- package/testing/matchers/toEqualStrictTyped.js +40 -0
- package/testing/matchers/toEqualStrictTyped.js.map +1 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/__cjs/react/types/types.d.cts +0 -661
- package/react/types/types.d.ts +0 -661
- /package/__cjs/react/{types → internal}/types.cjs +0 -0
- /package/__cjs/react/{types → internal}/types.cjs.map +0 -0
- /package/react/{types → internal}/types.js +0 -0
- /package/react/{types → internal}/types.js.map +0 -0
|
@@ -15,6 +15,7 @@ const invariant_1 = require("@apollo/client/utilities/invariant");
|
|
|
15
15
|
const equalByQuery_js_1 = require("./equalByQuery.cjs");
|
|
16
16
|
const networkStatus_js_1 = require("./networkStatus.cjs");
|
|
17
17
|
const { assign, hasOwnProperty } = Object;
|
|
18
|
+
const newNetworkStatusSymbol = Symbol();
|
|
18
19
|
class ObservableQuery {
|
|
19
20
|
options;
|
|
20
21
|
queryId;
|
|
@@ -84,6 +85,7 @@ class ObservableQuery {
|
|
|
84
85
|
this.options.notifyOnNetworkStatusChange) ||
|
|
85
86
|
// TODO: Remove this behavior when unifying loading state for notifyOnNetworkStatusChange
|
|
86
87
|
(this.options.fetchPolicy === "network-only" &&
|
|
88
|
+
!this.queryManager.prioritizeCacheValues &&
|
|
87
89
|
this.queryInfo.getDiff().complete) ||
|
|
88
90
|
result !== this.initialResult));
|
|
89
91
|
this["@@observable"] = () => this;
|
|
@@ -141,7 +143,11 @@ class ObservableQuery {
|
|
|
141
143
|
loading: (0, networkStatus_js_1.isNetworkRequestInFlight)(networkStatus),
|
|
142
144
|
networkStatus,
|
|
143
145
|
};
|
|
144
|
-
|
|
146
|
+
let { fetchPolicy = "cache-first" } = this.options;
|
|
147
|
+
const { prioritizeCacheValues } = this.queryManager;
|
|
148
|
+
if (prioritizeCacheValues) {
|
|
149
|
+
fetchPolicy = "cache-first";
|
|
150
|
+
}
|
|
145
151
|
if (
|
|
146
152
|
// These fetch policies should never deliver data from the cache, unless
|
|
147
153
|
// redelivering a previously delivered result.
|
|
@@ -153,7 +159,7 @@ class ObservableQuery {
|
|
|
153
159
|
this.queryManager.getDocumentInfo(this.query).hasForcedResolvers) {
|
|
154
160
|
// Fall through.
|
|
155
161
|
}
|
|
156
|
-
else if (this.waitForOwnResult) {
|
|
162
|
+
else if (this.waitForOwnResult && !prioritizeCacheValues) {
|
|
157
163
|
// This would usually be a part of `QueryInfo.getDiff()`.
|
|
158
164
|
// which we skip in the waitForOwnResult case since we are not
|
|
159
165
|
// interested in the diff.
|
|
@@ -276,7 +282,10 @@ class ObservableQuery {
|
|
|
276
282
|
};
|
|
277
283
|
}
|
|
278
284
|
this.queryInfo.resetLastWrite();
|
|
279
|
-
return this.reobserve(
|
|
285
|
+
return this.reobserve({
|
|
286
|
+
...reobserveOptions,
|
|
287
|
+
[newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.refetch,
|
|
288
|
+
});
|
|
280
289
|
}
|
|
281
290
|
/**
|
|
282
291
|
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
|
@@ -450,9 +459,7 @@ class ObservableQuery {
|
|
|
450
459
|
}
|
|
451
460
|
};
|
|
452
461
|
}
|
|
453
|
-
|
|
454
|
-
return this.reobserve(newOptions);
|
|
455
|
-
}
|
|
462
|
+
/** @internal */
|
|
456
463
|
silentSetOptions(newOptions) {
|
|
457
464
|
const mergedOptions = (0, utilities_1.compact)(this.options, newOptions || {});
|
|
458
465
|
assign(this.options, mergedOptions);
|
|
@@ -491,7 +498,8 @@ class ObservableQuery {
|
|
|
491
498
|
// Reset options.fetchPolicy to its original value.
|
|
492
499
|
fetchPolicy: this.options.initialFetchPolicy,
|
|
493
500
|
variables,
|
|
494
|
-
|
|
501
|
+
[newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.setVariables,
|
|
502
|
+
});
|
|
495
503
|
}
|
|
496
504
|
/**
|
|
497
505
|
* A function that enables you to update the query's cached result without executing a followup GraphQL operation.
|
|
@@ -556,7 +564,7 @@ class ObservableQuery {
|
|
|
556
564
|
// requests to be triggered only if the cache result is incomplete. To
|
|
557
565
|
// that end, the options.nextFetchPolicy option provides an easy way to
|
|
558
566
|
// update options.fetchPolicy after the initial network request, without
|
|
559
|
-
// having to call observableQuery.
|
|
567
|
+
// having to call observableQuery.reobserve.
|
|
560
568
|
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
561
569
|
reason,
|
|
562
570
|
options,
|
|
@@ -611,7 +619,8 @@ class ObservableQuery {
|
|
|
611
619
|
fetchPolicy: this.options.initialFetchPolicy === "no-cache" ?
|
|
612
620
|
"no-cache"
|
|
613
621
|
: "network-only",
|
|
614
|
-
|
|
622
|
+
[newNetworkStatusSymbol]: networkStatus_js_1.NetworkStatus.poll,
|
|
623
|
+
}).then(poll, poll);
|
|
615
624
|
}
|
|
616
625
|
else {
|
|
617
626
|
poll();
|
|
@@ -641,10 +650,20 @@ class ObservableQuery {
|
|
|
641
650
|
...(error ? { error } : null),
|
|
642
651
|
});
|
|
643
652
|
}
|
|
653
|
+
/**
|
|
654
|
+
* Reevaluate the query, optionally against new options. New options will be
|
|
655
|
+
* merged with the current options when given.
|
|
656
|
+
*/
|
|
644
657
|
// TODO: catch `EmptyError` and rethrow as network error if `complete`
|
|
645
658
|
// notification is emitted without a value.
|
|
646
|
-
reobserve(newOptions
|
|
659
|
+
reobserve(newOptions) {
|
|
647
660
|
this.isTornDown = false;
|
|
661
|
+
let newNetworkStatus;
|
|
662
|
+
if (newOptions) {
|
|
663
|
+
newNetworkStatus = newOptions[newNetworkStatusSymbol];
|
|
664
|
+
// Avoid setting the symbol option in this.options
|
|
665
|
+
delete newOptions[newNetworkStatusSymbol];
|
|
666
|
+
}
|
|
648
667
|
const useDisposableObservable =
|
|
649
668
|
// Refetching uses a disposable Observable to allow refetches using different
|
|
650
669
|
// options/variables, without permanently altering the options of the
|