@apollo/client 3.12.11 → 3.13.0-rc.0
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/blue-comics-train.md +7 -0
- package/.changeset/bright-guests-chew.md +16 -0
- package/.changeset/fluffy-worms-fail.md +5 -0
- package/.changeset/heavy-pumas-boil.md +6 -0
- package/.changeset/khaki-cars-develop.md +7 -0
- package/.changeset/pre.json +18 -0
- package/.changeset/pretty-planets-cough.md +24 -0
- package/.changeset/quiet-apricots-reply.md +6 -0
- package/.changeset/sharp-windows-switch.md +5 -0
- package/.changeset/tough-years-destroy.md +5 -0
- package/CHANGELOG.md +64 -0
- package/apollo-client.cjs +192 -20
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/config/jest/setup.js +2 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ObservableQuery.d.ts +3 -6
- package/core/ObservableQuery.js +6 -8
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.js +9 -4
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +16 -13
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +16 -13
- package/core/index.d.ts +2 -2
- package/core/index.js.map +1 -1
- package/core/watchQueryOptions.d.ts +50 -4
- 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/package.json +1 -1
- package/react/hoc/types.d.ts +2 -3
- package/react/hoc/types.js.map +1 -1
- package/react/hooks/hooks.cjs +53 -7
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +53 -7
- 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/internal/wrapHook.d.ts +2 -1
- package/react/hooks/internal/wrapHook.js.map +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +2 -1
- package/react/hooks/useBackgroundQuery.js +3 -1
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +2 -1
- package/react/hooks/useLoadableQuery.js +3 -1
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.js +3 -3
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +2 -1
- package/react/hooks/useQueryRefHandlers.js +3 -1
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useSuspenseFragment.d.ts +33 -0
- package/react/hooks/useSuspenseFragment.js +49 -0
- package/react/hooks/useSuspenseFragment.js.map +1 -0
- package/react/hooks/useSuspenseQuery.d.ts +1 -1
- package/react/hooks/useSuspenseQuery.js +3 -1
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/FragmentReference.d.ts +37 -0
- package/react/internal/cache/FragmentReference.js +123 -0
- package/react/internal/cache/FragmentReference.js.map +1 -0
- package/react/internal/cache/SuspenseCache.d.ts +7 -2
- package/react/internal/cache/SuspenseCache.js +14 -0
- package/react/internal/cache/SuspenseCache.js.map +1 -1
- package/react/internal/cache/types.d.ts +8 -0
- package/react/internal/cache/types.js.map +1 -1
- package/react/internal/internal.cjs +124 -1
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +124 -1
- package/react/types/types.d.ts +24 -4
- package/react/types/types.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/version.js +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@apollo/client": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Fix the return type of the `updateQuery` function to allow for `undefined`. `updateQuery` had the ability to bail out of the update by returning a falsey value, but the return type enforced a query value.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
observableQuery.updateQuery((unsafePreviousData, { previousData, complete }) => {
|
|
9
|
+
if (!complete) {
|
|
10
|
+
// Bail out of the update by returning early
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// ...
|
|
15
|
+
});
|
|
16
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@apollo/client": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Deprecate option `ignoreResults` in `useMutation`.
|
|
6
|
+
Once this option is removed, existing code still using it might see increase in re-renders.
|
|
7
|
+
If you don't want to synchronize your component state with the mutation, please use `useApolloClient` to get your ApolloClient instance and call `client.mutate` directly.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mode": "pre",
|
|
3
|
+
"tag": "rc",
|
|
4
|
+
"initialVersions": {
|
|
5
|
+
"@apollo/client": "3.12.2"
|
|
6
|
+
},
|
|
7
|
+
"changesets": [
|
|
8
|
+
"blue-comics-train",
|
|
9
|
+
"bright-guests-chew",
|
|
10
|
+
"fluffy-worms-fail",
|
|
11
|
+
"heavy-pumas-boil",
|
|
12
|
+
"khaki-cars-develop",
|
|
13
|
+
"pretty-planets-cough",
|
|
14
|
+
"quiet-apricots-reply",
|
|
15
|
+
"sharp-windows-switch",
|
|
16
|
+
"tough-years-destroy"
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@apollo/client": minor
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Provide a more type-safe option for the previous data value passed to `observableQuery.updateQuery`. Using it could result in crashes at runtime as this callback could be called with partial data even though its type reported the value as a complete result.
|
|
6
|
+
|
|
7
|
+
The `updateQuery` callback function is now called with a new type-safe `previousData` property and a new `complete` property in the 2nd argument that determines whether `previousData` is a complete or partial result.
|
|
8
|
+
|
|
9
|
+
As a result of this change, it is recommended to use the `previousData` property passed to the 2nd argument of the callback rather than using the previous data value from the first argument since that value is not type-safe. The first argument is now deprecated and will be removed in a future version of Apollo Client.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
observableQuery.updateQuery((unsafePreviousData, { previousData, complete }) => {
|
|
13
|
+
previousData
|
|
14
|
+
// ^? TData | DeepPartial<TData> | undefined
|
|
15
|
+
|
|
16
|
+
if (complete) {
|
|
17
|
+
previousData
|
|
18
|
+
// ^? TData
|
|
19
|
+
} else {
|
|
20
|
+
previousData
|
|
21
|
+
// ^? DeepPartial<TData> | undefined
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
```
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
---
|
|
2
|
+
"@apollo/client": patch
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Fix the type of the `variables` property passed as the 2nd argument to the `subscribeToMore` callback. This was previously reported as the `variables` type for the subscription itself, but is now properly typed as the query `variables`.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
# @apollo/client
|
|
2
2
|
|
|
3
|
+
## 3.13.0-rc.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#12066](https://github.com/apollographql/apollo-client/pull/12066) [`c01da5d`](https://github.com/apollographql/apollo-client/commit/c01da5da639d4d9e882d380573b7876df4a1d65b) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Adds a new `useSuspenseFragment` hook.
|
|
8
|
+
|
|
9
|
+
`useSuspenseFragment` suspends until `data` is complete. It is a drop-in replacement for `useFragment` when you prefer to use Suspense to control the loading state of a fragment.
|
|
10
|
+
|
|
11
|
+
- [#12174](https://github.com/apollographql/apollo-client/pull/12174) [`ba5cc33`](https://github.com/apollographql/apollo-client/commit/ba5cc330f8734a989eef71e883861f848388ac0c) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Ensure errors thrown in the `onCompleted` callback from `useMutation` don't call `onError`.
|
|
12
|
+
|
|
13
|
+
- [#12340](https://github.com/apollographql/apollo-client/pull/12340) [`716d02e`](https://github.com/apollographql/apollo-client/commit/716d02ec9c5b1448f50cb50a0306a345310a2342) Thanks [@phryneas](https://github.com/phryneas)! - Deprecate the `onCompleted` and `onError` callbacks of `useQuery` and `useLazyQuery`.
|
|
14
|
+
For more context, please see the [related issue](https://github.com/apollographql/apollo-client/issues/12352) on GitHub.
|
|
15
|
+
|
|
16
|
+
- [#12276](https://github.com/apollographql/apollo-client/pull/12276) [`670f112`](https://github.com/apollographql/apollo-client/commit/670f112a7d9d85cb357eb279a488ac2c6d0137a9) Thanks [@Cellule](https://github.com/Cellule)! - Provide a more type-safe option for the previous data value passed to `observableQuery.updateQuery`. Using it could result in crashes at runtime as this callback could be called with partial data even though its type reported the value as a complete result.
|
|
17
|
+
|
|
18
|
+
The `updateQuery` callback function is now called with a new type-safe `previousData` property and a new `complete` property in the 2nd argument that determines whether `previousData` is a complete or partial result.
|
|
19
|
+
|
|
20
|
+
As a result of this change, it is recommended to use the `previousData` property passed to the 2nd argument of the callback rather than using the previous data value from the first argument since that value is not type-safe. The first argument is now deprecated and will be removed in a future version of Apollo Client.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
observableQuery.updateQuery(
|
|
24
|
+
(unsafePreviousData, { previousData, complete }) => {
|
|
25
|
+
previousData;
|
|
26
|
+
// ^? TData | DeepPartial<TData> | undefined
|
|
27
|
+
|
|
28
|
+
if (complete) {
|
|
29
|
+
previousData;
|
|
30
|
+
// ^? TData
|
|
31
|
+
} else {
|
|
32
|
+
previousData;
|
|
33
|
+
// ^? DeepPartial<TData> | undefined
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- [#12174](https://github.com/apollographql/apollo-client/pull/12174) [`ba5cc33`](https://github.com/apollographql/apollo-client/commit/ba5cc330f8734a989eef71e883861f848388ac0c) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Reject the mutation promise if errors are thrown in the `onCompleted` callback of `useMutation`.
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- [#12276](https://github.com/apollographql/apollo-client/pull/12276) [`670f112`](https://github.com/apollographql/apollo-client/commit/670f112a7d9d85cb357eb279a488ac2c6d0137a9) Thanks [@Cellule](https://github.com/Cellule)! - Fix the return type of the `updateQuery` function to allow for `undefined`. `updateQuery` had the ability to bail out of the update by returning a falsey value, but the return type enforced a query value.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
observableQuery.updateQuery(
|
|
47
|
+
(unsafePreviousData, { previousData, complete }) => {
|
|
48
|
+
if (!complete) {
|
|
49
|
+
// Bail out of the update by returning early
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ...
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- [#12296](https://github.com/apollographql/apollo-client/pull/12296) [`2422df2`](https://github.com/apollographql/apollo-client/commit/2422df202a7ec71365d5a8ab5b3b554fcf60e4af) Thanks [@Cellule](https://github.com/Cellule)! - Deprecate option `ignoreResults` in `useMutation`.
|
|
59
|
+
Once this option is removed, existing code still using it might see increase in re-renders.
|
|
60
|
+
If you don't want to synchronize your component state with the mutation, please use `useApolloClient` to get your ApolloClient instance and call `client.mutate` directly.
|
|
61
|
+
|
|
62
|
+
- [#12338](https://github.com/apollographql/apollo-client/pull/12338) [`67c16c9`](https://github.com/apollographql/apollo-client/commit/67c16c93897e36be980ba2139ee8bd3f24ab8558) Thanks [@phryneas](https://github.com/phryneas)! - In case of a multipart response (e.g. with `@defer`), query deduplication will
|
|
63
|
+
now keep going until the final chunk has been received.
|
|
64
|
+
|
|
65
|
+
- [#12276](https://github.com/apollographql/apollo-client/pull/12276) [`670f112`](https://github.com/apollographql/apollo-client/commit/670f112a7d9d85cb357eb279a488ac2c6d0137a9) Thanks [@Cellule](https://github.com/Cellule)! - Fix the type of the `variables` property passed as the 2nd argument to the `subscribeToMore` `updateQuery` callback. This was previously reported as the `variables` type for the subscription itself, but is now properly typed as the query `variables`.
|
|
66
|
+
|
|
3
67
|
## 3.12.11
|
|
4
68
|
|
|
5
69
|
### Patch Changes
|
package/apollo-client.cjs
CHANGED
|
@@ -30,8 +30,9 @@ function _interopNamespace(e) {
|
|
|
30
30
|
|
|
31
31
|
var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
|
|
32
32
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
33
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
33
34
|
|
|
34
|
-
var version = "3.
|
|
35
|
+
var version = "3.13.0-rc.0";
|
|
35
36
|
|
|
36
37
|
function maybe(thunk) {
|
|
37
38
|
try {
|
|
@@ -5455,12 +5456,8 @@ var ObservableQuery = (function (_super) {
|
|
|
5455
5456
|
next: function (subscriptionData) {
|
|
5456
5457
|
var updateQuery = options.updateQuery;
|
|
5457
5458
|
if (updateQuery) {
|
|
5458
|
-
_this.updateQuery(function (previous,
|
|
5459
|
-
|
|
5460
|
-
return updateQuery(previous, {
|
|
5461
|
-
subscriptionData: subscriptionData,
|
|
5462
|
-
variables: variables,
|
|
5463
|
-
});
|
|
5459
|
+
_this.updateQuery(function (previous, updateOptions) {
|
|
5460
|
+
return updateQuery(previous, tslib.__assign({ subscriptionData: subscriptionData }, updateOptions));
|
|
5464
5461
|
});
|
|
5465
5462
|
}
|
|
5466
5463
|
},
|
|
@@ -5501,14 +5498,16 @@ var ObservableQuery = (function (_super) {
|
|
|
5501
5498
|
};
|
|
5502
5499
|
ObservableQuery.prototype.updateQuery = function (mapFn) {
|
|
5503
5500
|
var queryManager = this.queryManager;
|
|
5504
|
-
var
|
|
5501
|
+
var _a = queryManager.cache.diff({
|
|
5505
5502
|
query: this.options.query,
|
|
5506
5503
|
variables: this.variables,
|
|
5507
5504
|
returnPartialData: true,
|
|
5508
5505
|
optimistic: false,
|
|
5509
|
-
}).result;
|
|
5506
|
+
}), result = _a.result, complete = _a.complete;
|
|
5510
5507
|
var newResult = mapFn(result, {
|
|
5511
5508
|
variables: this.variables,
|
|
5509
|
+
complete: !!complete,
|
|
5510
|
+
previousData: result,
|
|
5512
5511
|
});
|
|
5513
5512
|
if (newResult) {
|
|
5514
5513
|
queryManager.cache.writeQuery({
|
|
@@ -6677,12 +6676,17 @@ var QueryManager = (function () {
|
|
|
6677
6676
|
var entry = inFlightLinkObservables_1.lookup(printedServerQuery_1, varJson_1);
|
|
6678
6677
|
observable = entry.observable;
|
|
6679
6678
|
if (!observable) {
|
|
6680
|
-
var
|
|
6679
|
+
var concast_1 = new Concast([
|
|
6681
6680
|
execute(link, operation),
|
|
6682
6681
|
]);
|
|
6683
|
-
observable = entry.observable =
|
|
6684
|
-
|
|
6685
|
-
|
|
6682
|
+
observable = entry.observable = concast_1;
|
|
6683
|
+
concast_1.beforeNext(function cb(method, arg) {
|
|
6684
|
+
if (method === "next" && "hasNext" in arg && arg.hasNext) {
|
|
6685
|
+
concast_1.beforeNext(cb);
|
|
6686
|
+
}
|
|
6687
|
+
else {
|
|
6688
|
+
inFlightLinkObservables_1.remove(printedServerQuery_1, varJson_1);
|
|
6689
|
+
}
|
|
6686
6690
|
});
|
|
6687
6691
|
}
|
|
6688
6692
|
}
|
|
@@ -8330,10 +8334,10 @@ function useMutation(mutation, options) {
|
|
|
8330
8334
|
onCompleted === null || onCompleted === void 0 ? void 0 : onCompleted(response.data, clientOptions);
|
|
8331
8335
|
}
|
|
8332
8336
|
return response;
|
|
8333
|
-
})
|
|
8334
|
-
.catch(function (error) {
|
|
8337
|
+
}, function (error) {
|
|
8335
8338
|
var _a;
|
|
8336
|
-
if (mutationId === ref.current.mutationId &&
|
|
8339
|
+
if (mutationId === ref.current.mutationId &&
|
|
8340
|
+
ref.current.isMounted) {
|
|
8337
8341
|
var result_2 = {
|
|
8338
8342
|
loading: false,
|
|
8339
8343
|
error: error,
|
|
@@ -8877,10 +8881,121 @@ var InternalQueryReference = (function () {
|
|
|
8877
8881
|
return InternalQueryReference;
|
|
8878
8882
|
}());
|
|
8879
8883
|
|
|
8884
|
+
var FragmentReference = (function () {
|
|
8885
|
+
function FragmentReference(client, watchFragmentOptions, options) {
|
|
8886
|
+
var _this = this;
|
|
8887
|
+
this.key = {};
|
|
8888
|
+
this.listeners = new Set();
|
|
8889
|
+
this.references = 0;
|
|
8890
|
+
this.dispose = this.dispose.bind(this);
|
|
8891
|
+
this.handleNext = this.handleNext.bind(this);
|
|
8892
|
+
this.handleError = this.handleError.bind(this);
|
|
8893
|
+
this.observable = client.watchFragment(watchFragmentOptions);
|
|
8894
|
+
if (options.onDispose) {
|
|
8895
|
+
this.onDispose = options.onDispose;
|
|
8896
|
+
}
|
|
8897
|
+
var diff = this.getDiff(client, watchFragmentOptions);
|
|
8898
|
+
var startDisposeTimer = function () {
|
|
8899
|
+
var _a;
|
|
8900
|
+
if (!_this.references) {
|
|
8901
|
+
_this.autoDisposeTimeoutId = setTimeout(_this.dispose, (_a = options.autoDisposeTimeoutMs) !== null && _a !== void 0 ? _a : 30000);
|
|
8902
|
+
}
|
|
8903
|
+
};
|
|
8904
|
+
this.promise =
|
|
8905
|
+
diff.complete ?
|
|
8906
|
+
createFulfilledPromise(diff.result)
|
|
8907
|
+
: this.createPendingPromise();
|
|
8908
|
+
this.subscribeToFragment();
|
|
8909
|
+
this.promise.then(startDisposeTimer, startDisposeTimer);
|
|
8910
|
+
}
|
|
8911
|
+
FragmentReference.prototype.listen = function (listener) {
|
|
8912
|
+
var _this = this;
|
|
8913
|
+
this.listeners.add(listener);
|
|
8914
|
+
return function () {
|
|
8915
|
+
_this.listeners.delete(listener);
|
|
8916
|
+
};
|
|
8917
|
+
};
|
|
8918
|
+
FragmentReference.prototype.retain = function () {
|
|
8919
|
+
var _this = this;
|
|
8920
|
+
this.references++;
|
|
8921
|
+
clearTimeout(this.autoDisposeTimeoutId);
|
|
8922
|
+
var disposed = false;
|
|
8923
|
+
return function () {
|
|
8924
|
+
if (disposed) {
|
|
8925
|
+
return;
|
|
8926
|
+
}
|
|
8927
|
+
disposed = true;
|
|
8928
|
+
_this.references--;
|
|
8929
|
+
setTimeout(function () {
|
|
8930
|
+
if (!_this.references) {
|
|
8931
|
+
_this.dispose();
|
|
8932
|
+
}
|
|
8933
|
+
});
|
|
8934
|
+
};
|
|
8935
|
+
};
|
|
8936
|
+
FragmentReference.prototype.dispose = function () {
|
|
8937
|
+
this.subscription.unsubscribe();
|
|
8938
|
+
this.onDispose();
|
|
8939
|
+
};
|
|
8940
|
+
FragmentReference.prototype.onDispose = function () {
|
|
8941
|
+
};
|
|
8942
|
+
FragmentReference.prototype.subscribeToFragment = function () {
|
|
8943
|
+
this.subscription = this.observable.subscribe(this.handleNext.bind(this), this.handleError.bind(this));
|
|
8944
|
+
};
|
|
8945
|
+
FragmentReference.prototype.handleNext = function (result) {
|
|
8946
|
+
var _a;
|
|
8947
|
+
switch (this.promise.status) {
|
|
8948
|
+
case "pending": {
|
|
8949
|
+
if (result.complete) {
|
|
8950
|
+
return (_a = this.resolve) === null || _a === void 0 ? void 0 : _a.call(this, result.data);
|
|
8951
|
+
}
|
|
8952
|
+
this.deliver(this.promise);
|
|
8953
|
+
break;
|
|
8954
|
+
}
|
|
8955
|
+
case "fulfilled": {
|
|
8956
|
+
if (equal.equal(this.promise.value, result.data)) {
|
|
8957
|
+
return;
|
|
8958
|
+
}
|
|
8959
|
+
this.promise =
|
|
8960
|
+
result.complete ?
|
|
8961
|
+
createFulfilledPromise(result.data)
|
|
8962
|
+
: this.createPendingPromise();
|
|
8963
|
+
this.deliver(this.promise);
|
|
8964
|
+
}
|
|
8965
|
+
}
|
|
8966
|
+
};
|
|
8967
|
+
FragmentReference.prototype.handleError = function (error) {
|
|
8968
|
+
var _a;
|
|
8969
|
+
(_a = this.reject) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
8970
|
+
};
|
|
8971
|
+
FragmentReference.prototype.deliver = function (promise) {
|
|
8972
|
+
this.listeners.forEach(function (listener) { return listener(promise); });
|
|
8973
|
+
};
|
|
8974
|
+
FragmentReference.prototype.createPendingPromise = function () {
|
|
8975
|
+
var _this = this;
|
|
8976
|
+
return wrapPromiseWithState(new Promise(function (resolve, reject) {
|
|
8977
|
+
_this.resolve = resolve;
|
|
8978
|
+
_this.reject = reject;
|
|
8979
|
+
}));
|
|
8980
|
+
};
|
|
8981
|
+
FragmentReference.prototype.getDiff = function (client, options) {
|
|
8982
|
+
var cache = client.cache;
|
|
8983
|
+
var from = options.from, fragment = options.fragment, fragmentName = options.fragmentName;
|
|
8984
|
+
var diff = cache.diff(tslib.__assign(tslib.__assign({}, options), { query: cache["getFragmentDoc"](fragment, fragmentName), returnPartialData: true, id: from, optimistic: true }));
|
|
8985
|
+
return tslib.__assign(tslib.__assign({}, diff), { result: client["queryManager"].maskFragment({
|
|
8986
|
+
fragment: fragment,
|
|
8987
|
+
fragmentName: fragmentName,
|
|
8988
|
+
data: diff.result,
|
|
8989
|
+
}) });
|
|
8990
|
+
};
|
|
8991
|
+
return FragmentReference;
|
|
8992
|
+
}());
|
|
8993
|
+
|
|
8880
8994
|
var SuspenseCache = (function () {
|
|
8881
8995
|
function SuspenseCache(options) {
|
|
8882
8996
|
if (options === void 0) { options = Object.create(null); }
|
|
8883
8997
|
this.queryRefs = new trie.Trie(canUseWeakMap);
|
|
8998
|
+
this.fragmentRefs = new trie.Trie(canUseWeakMap);
|
|
8884
8999
|
this.options = options;
|
|
8885
9000
|
}
|
|
8886
9001
|
SuspenseCache.prototype.getQueryRef = function (cacheKey, createObservable) {
|
|
@@ -8895,6 +9010,18 @@ var SuspenseCache = (function () {
|
|
|
8895
9010
|
}
|
|
8896
9011
|
return ref.current;
|
|
8897
9012
|
};
|
|
9013
|
+
SuspenseCache.prototype.getFragmentRef = function (cacheKey, client, options) {
|
|
9014
|
+
var ref = this.fragmentRefs.lookupArray(cacheKey);
|
|
9015
|
+
if (!ref.current) {
|
|
9016
|
+
ref.current = new FragmentReference(client, options, {
|
|
9017
|
+
autoDisposeTimeoutMs: this.options.autoDisposeTimeoutMs,
|
|
9018
|
+
onDispose: function () {
|
|
9019
|
+
delete ref.current;
|
|
9020
|
+
},
|
|
9021
|
+
});
|
|
9022
|
+
}
|
|
9023
|
+
return ref.current;
|
|
9024
|
+
};
|
|
8898
9025
|
SuspenseCache.prototype.add = function (cacheKey, queryRef) {
|
|
8899
9026
|
var ref = this.queryRefs.lookupArray(cacheKey);
|
|
8900
9027
|
ref.current = queryRef;
|
|
@@ -8974,7 +9101,8 @@ function useSuspenseQuery_(query, options) {
|
|
|
8974
9101
|
setPromise([queryRef.key, queryRef.promise]);
|
|
8975
9102
|
return promise;
|
|
8976
9103
|
}, [queryRef]);
|
|
8977
|
-
var subscribeToMore = queryRef.observable
|
|
9104
|
+
var subscribeToMore = queryRef.observable
|
|
9105
|
+
.subscribeToMore;
|
|
8978
9106
|
return React__namespace.useMemo(function () {
|
|
8979
9107
|
return {
|
|
8980
9108
|
client: client,
|
|
@@ -9086,11 +9214,52 @@ function useBackgroundQuery_(query, options) {
|
|
|
9086
9214
|
{
|
|
9087
9215
|
fetchMore: fetchMore,
|
|
9088
9216
|
refetch: refetch,
|
|
9089
|
-
subscribeToMore: queryRef.observable
|
|
9217
|
+
subscribeToMore: queryRef.observable
|
|
9218
|
+
.subscribeToMore,
|
|
9090
9219
|
},
|
|
9091
9220
|
];
|
|
9092
9221
|
}
|
|
9093
9222
|
|
|
9223
|
+
var NULL_PLACEHOLDER = [];
|
|
9224
|
+
function useSuspenseFragment(options) {
|
|
9225
|
+
return wrapHook("useSuspenseFragment",
|
|
9226
|
+
useSuspenseFragment_, useApolloClient(typeof options === "object" ? options.client : undefined))(options);
|
|
9227
|
+
}
|
|
9228
|
+
function useSuspenseFragment_(options) {
|
|
9229
|
+
var client = useApolloClient(options.client);
|
|
9230
|
+
var from = options.from;
|
|
9231
|
+
var cache = client.cache;
|
|
9232
|
+
var id = React.useMemo(function () {
|
|
9233
|
+
return typeof from === "string" ? from
|
|
9234
|
+
: from === null ? null
|
|
9235
|
+
: cache.identify(from);
|
|
9236
|
+
}, [cache, from]);
|
|
9237
|
+
var fragmentRef = id === null ? null : (getSuspenseCache(client).getFragmentRef([id, options.fragment, canonicalStringify(options.variables)], client, tslib.__assign(tslib.__assign({}, options), { from: id })));
|
|
9238
|
+
var _a = React__default.useState(fragmentRef === null ? NULL_PLACEHOLDER : ([fragmentRef.key, fragmentRef.promise])), current = _a[0], setPromise = _a[1];
|
|
9239
|
+
React__default.useEffect(function () {
|
|
9240
|
+
if (fragmentRef === null) {
|
|
9241
|
+
return;
|
|
9242
|
+
}
|
|
9243
|
+
var dispose = fragmentRef.retain();
|
|
9244
|
+
var removeListener = fragmentRef.listen(function (promise) {
|
|
9245
|
+
setPromise([fragmentRef.key, promise]);
|
|
9246
|
+
});
|
|
9247
|
+
return function () {
|
|
9248
|
+
dispose();
|
|
9249
|
+
removeListener();
|
|
9250
|
+
};
|
|
9251
|
+
}, [fragmentRef]);
|
|
9252
|
+
if (fragmentRef === null) {
|
|
9253
|
+
return { data: null };
|
|
9254
|
+
}
|
|
9255
|
+
if (current[0] !== fragmentRef.key) {
|
|
9256
|
+
current[0] = fragmentRef.key;
|
|
9257
|
+
current[1] = fragmentRef.promise;
|
|
9258
|
+
}
|
|
9259
|
+
var data = __use(current[1]);
|
|
9260
|
+
return { data: data };
|
|
9261
|
+
}
|
|
9262
|
+
|
|
9094
9263
|
function useLoadableQuery(query, options) {
|
|
9095
9264
|
if (options === void 0) { options = Object.create(null); }
|
|
9096
9265
|
var client = useApolloClient(options.client);
|
|
@@ -9146,7 +9315,8 @@ function useLoadableQuery(query, options) {
|
|
|
9146
9315
|
]);
|
|
9147
9316
|
var subscribeToMore = React__namespace.useCallback(function (options) {
|
|
9148
9317
|
invariant(internalQueryRef, 60);
|
|
9149
|
-
return internalQueryRef.observable.subscribeToMore(
|
|
9318
|
+
return internalQueryRef.observable.subscribeToMore(
|
|
9319
|
+
options);
|
|
9150
9320
|
}, [internalQueryRef]);
|
|
9151
9321
|
var reset = React__namespace.useCallback(function () {
|
|
9152
9322
|
setQueryRef(null);
|
|
@@ -9187,7 +9357,8 @@ function useQueryRefHandlers_(queryRef) {
|
|
|
9187
9357
|
return {
|
|
9188
9358
|
refetch: refetch,
|
|
9189
9359
|
fetchMore: fetchMore,
|
|
9190
|
-
subscribeToMore: internalQueryRef.observable
|
|
9360
|
+
subscribeToMore: internalQueryRef.observable
|
|
9361
|
+
.subscribeToMore,
|
|
9191
9362
|
};
|
|
9192
9363
|
}
|
|
9193
9364
|
|
|
@@ -9300,5 +9471,6 @@ exports.useQueryRefHandlers = useQueryRefHandlers;
|
|
|
9300
9471
|
exports.useReactiveVar = useReactiveVar;
|
|
9301
9472
|
exports.useReadQuery = useReadQuery;
|
|
9302
9473
|
exports.useSubscription = useSubscription;
|
|
9474
|
+
exports.useSuspenseFragment = useSuspenseFragment;
|
|
9303
9475
|
exports.useSuspenseQuery = useSuspenseQuery;
|
|
9304
9476
|
//# sourceMappingURL=apollo-client.cjs.map
|